c# - Filling list with Json data and getting the objects from it -


i have php webservice gets data database , returns json data.

json data

{"faqs":    [         {"faq":{"id":"123"}},         {"faq":{"id":"124"}}    ] } 

object classes

public class faqlist {     public list<faq> faqs { get; set; } } public class faq {     public string id { get; set; } } 

test class

var client = new httpclient(); httpresponsemessage response = await client.getasync(new uri("http://www.mydomain.com/webservice/7/server.php")); var jsonstring = await response.content.readasstringasync();  faqlist list = jsonconvert.deserializeobject<faqlist>(jsonstring);  list.faqs.count() => 2 list.faqs[0].id   => null !! 

i fill objects 'list'. count test see it's filled. if try objects it, null error.

so, how can correctly fill list can objects it?

http://json2csharp.com/ suggests these definitions. (one more class faq2)

public class faq2 {     public string id { get; set; } }  public class faq {     public faq2 faq { get; set; } }  public class rootobject {     public list<faq> faqs { get; set; } } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -