从多个 json 数组 C# 中解析数据
Parse data from multiple json arrays C#
我有这个 JSON,我正在尝试获取每个名称、地点 ID、创建者姓名等
从 JSON 数据中,我还没有弄清楚如何,我正在使用 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; }
}
我有这个 JSON,我正在尝试获取每个名称、地点 ID、创建者姓名等 从 JSON 数据中,我还没有弄清楚如何,我正在使用 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; }
}