-1

Example JSON data:

{"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]}

I found the Newtonsoft JSON.NET deserialize library for C#. If I use:

object JsonDe = JsonConvert.DeserializeObject(Json); 

How can I access to the JsonDe object to get all the "Type" Data without creating a class?

The provided JSON is only an example, I have to manage a large JSON response from website an creating a class would be hard work.

stuartd
  • 70,509
  • 14
  • 132
  • 163
NeDark
  • 1,212
  • 7
  • 23
  • 36
  • 1
    Creating a class for JSON is *not* hard work - you can paste the JSOn into Visual Studio and it will create the class(es) for you. – Ňɏssa Pøngjǣrdenlarp Aug 13 '19 at 17:42
  • you can covert it into Dictionary – Fajar AM Aug 13 '19 at 17:46
  • You can use `JToken.Parse()` or `JsonConvert.DeserializeObject(Json)` to parse JSON with no fixed schema. See: [JObject.Parse vs JsonConvert.DeserializeObject](https://stackoverflow.com/a/24645588). – dbc Aug 13 '19 at 17:47
  • Incidentally, you don't need to create a class for the *entire* data. You could just create classes with the require data. The rest will be ignored. – dbc Aug 13 '19 at 17:49
  • @ŇɏssaPøngjǣrdenlarp How can I do that? – NeDark Aug 13 '19 at 17:50
  • Creating class file for JSON (no matter how large) is not that hard. https://stackoverflow.com/questions/53119308/why-are-the-paste-json-as-classes-and-paste-xml-as-classes-commands-disabled – Vidhyardhi Gorrepati Aug 13 '19 at 17:59
  • @NeDark - see [How to auto-generate a C# class file from a JSON string](https://stackoverflow.com/q/21611674/3744182). – dbc Aug 13 '19 at 18:02
  • I think class is definetly the best way to go. and as @dbc said "You could just create classes with the required data." meaning you could just create a class with your "Type" property otherwise you could try from the Newtonsoft.Json.Linq namespace `dynamic d = JObject.Parse({"t":"1339886","a":true,"data":[],"Type":[['Ants','Biz','Tro']]});` and use it like `d.Type` – D. Dahlberg Aug 13 '19 at 19:10

1 Answers1

3

Have you looked into using JsonLinq and JObject.Parse()? You can then using something like the following:

string Data = "{\"t\":\"1339886\",\"a\":true,\"data\":[],\"Type\":[['Ants','Biz','Tro']]}";
JObject J = JObject.Parse(Data);
string[] Types = J["Type"][0].ToObject<string[]>();

Note: I didn't test this against your data structure.

Chris
  • 733
  • 1
  • 5
  • 19