looping through json array in c# -
i have json string like,
{"objecttype" : "subscriber", "objectlist":[{"firstname":"name1","email":"email@example.com","address":"exampleaddress"},{"firstname":"name2","email":"email2@example.com","address":"exampleaddress2"}]} i need parse in c# code. have tried,
javascriptserializer json_serializer = new javascriptserializer(); object routes_list = json_serializer.deserializeobject(myjson here); but cant loop through "objectlist" array. how can done?
var jsonobj = new javascriptserializer().deserialize<rootobj>(json); foreach (var obj in jsonobj.objectlist) { console.writeline(obj.address); } public class objectlist { public string firstname { get; set; } public string email { get; set; } public string address { get; set; } } public class rootobj { public string objecttype { get; set; } public list<objectlist> objectlist { get; set; } } hint: can use this site convert json string c# classes
edit
using json.net
dynamic jsonobj = jsonconvert.deserializeobject(json); foreach (var obj in jsonobj.objectlist) { console.writeline(obj.address); }
Comments
Post a Comment