c# - read multiple Json data from webservice -
i have web service returns json string. problem have difficulties read it
i tried with:
javascriptserializer jsserializer = new javascriptserializer(); string jsondata = reader.readtoend(); var myobj = jsserializer.deserialize<list<cinforichiesta>>(jsondata);
but how can values "students" , "locations"? javascript used :" var j = jquery.parsejson(msg.d);" think c# code different
this example of string:
{"questions":{ "id":"2", "book":"3", "students":{ "class":"3", "theme","43" }, "locations":{ "h":"0", "l":"3" } } }
first off, json isn't valid thats first problem have. can verify @ http://jsonlint.com/ example.
i have fixed in following way:
{ "questions": { "id": "2", "book": "3", "students": { "class": "3", "theme": "na", "43": "na" }, "locations": { "h": "0", "l": "3" } } }
second class should correct, current json should this
public class rootobject { public questions questions { get; set; } } public class questions { public string id { get; set; } public string book { get; set; } public students students { get; set; } public locations locations { get; set; } } public class students { public string _class { get; set; } public string theme { get; set; } public string _43 { get; set; } } public class locations { public string h { get; set; } public string l { get; set; } }
after can deserialize this
var myobj = jsserializer.deserialize<list<rootobject>>(jsondata);
and can information this
myobj.questions.students._class
Comments
Post a Comment