2

I have this JSON, and I'm trying to get each name, and place id, creator name, etcetera from the JSON data, I haven't figured out how to, I am using Newtonsoft.Json so then I will be able to write them in the console together.

Here's the 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
}
  • Create a class structure which matches this structure and deserialize the JSON string to an instance of that class. Then you can use/manipulate the data on that object as needed. – David Jun 01 '22 at 15:34
  • https://json2csharp.com/ – Lee Taylor Jun 01 '22 at 15:35
  • Sorry i'm new in Newtonsoft.JSON how do I do that? – Kenka Williams Jun 01 '22 at 15:36
  • https://stackoverflow.com/questions/34103498/how-do-i-deserialize-a-json-array-using-newtonsoft-json – urlreader Jun 01 '22 at 15:43
  • I'm trying to parse multiple like 100 rows as I am scraping these. – Kenka Williams Jun 01 '22 at 15:48
  • Take a look at [How to auto-generate a C# class file from a JSON string](https://stackoverflow.com/q/21611674/3744182) as well as [Convert JSON String To C# Object](https://stackoverflow.com/a/14904115/3744182). – dbc Jun 01 '22 at 16:13

1 Answers1

1

there are a lot of ways to get data from json. It depends what do you need. For example you can learn this

    List<Game> games = JObject.Parse(json)["games"].ToObject<List<Game>>();

how to use

    Game game = games.Where(g => g.name == "Char les C3lvin Memorial").FirstOrDefault();

Game 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; }
}
Serge
  • 40,935
  • 4
  • 18
  • 45