[英]Parse data from multiple json arrays C#
我有這個 JSON,我正在嘗試從 JSON 數據中獲取每個名稱、地點 ID、創建者姓名等,我還沒有弄清楚如何,我正在使用 Newtonsoft.Json 這樣我就可以將它們一起寫在控制台中。
這是 JSON
{
"games": [
{
"creatorId": 209596022,
"creatorType": "User",
"totalUpVotes": 12,
"totalDownVotes": 1,
"universeId": 2044766328,
"name": "Char les Calvin Memorial",
"placeId": 5764830729,
"playerCount": 0,
"price": null,
"analyticsIdentifier": null,
"gameDescription": "test",
"genre": ""
},
{
"creatorId": 209596022,
"creatorType": "User",
"totalUpVotes": 13,
"totalDownVotes": 2,
"universeId": 2043766328,
"name": "Char les C3lvin Memorial",
"placeId": 5763830729,
"playerCount": 0,
"price": null,
"analyticsIdentifier": null,
"gameDescription": "tedst",
"genre": ""
}
],
"suggestedKeyword": null,
"correctedKeyword": null,
"filteredKeyword": null,
"hasMoreRows": true,
"nextPageExclusiveStartId": null,
"featuredSearchUniverseId": null,
"emphasis": false,
"cutOffIndex": null,
"algorithm": "GameSearchUsingSimilarQueryService",
"algorithmQueryType": "Bucketboost",
"suggestionAlgorithm": "GameSuggestions_V2",
"relatedGames": [],
"esDebugInfo": null
}
從json獲取數據的方法有很多種,看你需要什么。 例如你可以學習這個
List<Game> games = JObject.Parse(json)["games"].ToObject<List<Game>>();
如何使用
Game game = games.Where(g => g.name == "Char les C3lvin Memorial").FirstOrDefault();
游戲 class
public class Game
{
public int creatorId { get; set; }
public string creatorType { get; set; }
public int totalUpVotes { get; set; }
public int totalDownVotes { get; set; }
public int universeId { get; set; }
public string name { get; set; }
public object placeId { get; set; }
public int playerCount { get; set; }
public object price { get; set; }
public object analyticsIdentifier { get; set; }
public string gameDescription { get; set; }
public string genre { get; set; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.