Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newtonsoft JSON Deserialize

My JSON is as follows:

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

I found the Newtonsoft JSON.NET deserialize library for C#. I tried to use it as follow:

object JsonDe = JsonConvert.DeserializeObject(Json);  

How can I access to the JsonDe object to get all the "Type" Data? I tried it with a loop but it is not working because the object does not have an enumerator.

like image 984
abc cba Avatar asked Jun 11 '13 07:06

abc cba


1 Answers

You can implement a class that holds the fields you have in your JSON

class MyData {     public string t;     public bool a;     public object[] data;     public string[][] type; } 

and then use the generic version of DeserializeObject:

MyData tmp = JsonConvert.DeserializeObject<MyData>(json); foreach (string typeStr in tmp.type[0]) {     // Do something with typeStr } 

Documentation: Serializing and Deserializing JSON

like image 136
Michael Banzon Avatar answered Oct 10 '22 10:10

Michael Banzon