c# - Deserialize nested JSON array using RestSharp -


having following json array:

[{ "name": "component1", "count": 2, "bulletins": [{     "referencenumber": "00000a57",     "title": "test test test",     "publicationdate": "2014-07-02",     "list": ["00000a57"] }, {     "referencenumber": "10v240000",     "title": "bla bla bla",     "publicationdate": "2010-06-04",     "list": ["10v240000"] }] }, { "name": "component2", "count": 2, "bulletins": [{     "referencenumber": "00-00-0a-57",     "title": "information regarding bla bla",     "publicationdate": "2015-05-22",     "list": ["15-00-89-004",     "15-00-89-004a"] }, {     "referencenumber": "01-02-0b-57",     "title": "unscheduled supplemental services",     "publicationdate": "2012-09-28",     "list": ["04-06-01-029",     "04-26-51-029",     "04-26-51-029",     "04-26-51-029",     "04-26-51-029",     "04-26-51-029",     "04-26-51-029"] }] }] 

i'm using following code retrieve name , count values:

public class bulletinsitemsname {     public string name { get; set; }     public string count { get; set; }     public list<bulletinscontainer> blt { get; set; } }  public class bulletinscontainer {     public bulletins bulletins; }  public class bulletins {     public string referencenumber { get; set; }     public string title { get; set; }     public string publicationdate { get; set; }     public string supersededlist { get; set; } } 

to run request have:

var req = request.execute<list<bulletinsitemsname>>(parameters); 

and list values:

foreach(var xx in req.data) {     console.writeline(xx.name);      foreach(var yz in xx.blt) // object reference not set instance of object      {          console.writeline(yz.bulletins.title);      } } 

how can values for: referencenumber, title, publicationdate , list? values correctly returned name , count when want bulletins values following error thrown: object reference not set instance of object.

try using list of bulletins instead of bulletinscontainer - it's morning me, can't see why need bulletinscontainer

public list<bulletins> blt { get; set; } 

i recommend, if possible, name classes in singular form.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -