Parsing JSON multidimensional array with C# -


i'm trying parsing data json file i'm getting problems.

this sample data json file data source

and code:

foreach (jsonvalue groupvalue in jsonarray) {     jsonobject groupobject = groupvalue.getobject();     dadoslocaisinteresse group =          new dadoslocaisinteresse(             groupobject["uniqueid"].getstring(),             groupobject["title"].getstring(),             groupobject["subtitle"].getstring(),             groupobject["imagepath"].getstring(),             groupobject["description"].getstring(),             groupobject["latitude"].getnumber(),             groupobject["longitude"].getnumber()     );      foreach (jsonvalue itemvalue in groupobject["items"].getarray())     {         jsonobject itemobject = itemvalue.getobject();          group.items.add(             new dadoslocaisinteressepontos(                 itemobject["uniqueid"].getstring(),                 itemobject["title"].getstring(),                 itemobject["subtitle"].getstring(),                 itemobject["imagepath"].getstring(),                 itemobject["description"].getstring(),                 itemobject["content"].getstring(),                 itemobject["itemlatitude"].getnumber(),                 itemobject["itemlongitude"].getnumber())         );          foreach (jsonvalue galeriavalue in itemobject["galerias"].getarray())         {             jsonobject galeriaobject = galeriavalue.getobject();             itemsgaleria galeria =                  new itemsgaleria(                     galeriaobject["uniqueid"].getstring(),                     galeriaobject["imagepath"].getstring(),                     galeriaobject["imagepath1"].getstring()             );                                     }     }     this.groups.add(group); } 

the groups , items arrays works fine. problem can't data "galeria array"... i'm doing wrong???

you can use below mentioned method deserializeobject

you have create class can contain properties :

 public class grp {      public string uniqueid { get; set; }     public string title { get; set; }     public string subtitle { get; set; }     private list<item> _items=new list<item>();      public list<item> items     {         { return _items; }         set { _items = value; }     }   }  public class item {     public string uniqueid { get; set; }     public string title { get; set; }     public string subtitle { get; set; } } 

and can add using newtonsoft.json; deserializeobject;

var obj = jsonconvert.deserializeobject<grp>(s); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -