C# JSON deserializing to Custom Class -
i deserialize json object this:
[{"response":"ok","uuid":"89172"},{"response":"ok","uuid":"10304"}]
into custom class has variables storing response , uuid. want deserialize multiple data response such above example. great if can use method foreach such can pop data out accordingly. can advise? many thanks!
write class
public class myclass {    public string response { get; set; }    public string uuid { get; set; } }   then can deserialize using library newtonsoft.json
string jsonstring = "[{"response":"ok","uuid":"89172"},{"response":"ok","uuid":"10304"}]"; ... ... var mylistofitems= jsonconvert.deserializeobject<list<myclass>>(jsonstring);  foreach(var item in mylistofitems) {    .... }   full code in console application
using system; using system.collections.generic; using system.linq; using system.text; using newtonsoft.json;  namespace consoleapplication1 { class program {     static void main(string[] args)     {         string jsonstring = "[{'response':'ok','uuid':'89172'},{'response':'ok','uuid':'10304'}]";          var items= jsonconvert.deserializeobject<list<myclass>>(jsonstring);          foreach (var item in items)         {             console.writeline("uuuid: "+item.uuid);             console.writeline("response: " + item.response);             console.writeline();         }          console.readkey();     } }  public class myclass  {     public string response { get; set; }     public string uuid { get; set; }  } }      
Comments
Post a Comment