c# - Deserialize array of json objects with json object inside -
c# - Deserialize array of json objects with json object inside -
how can deserialize array of json objects in c#? here's json:
[{"id":"255521115", "user":"username","userinfo":{"id":"158","online":"false"}}]
i have code username:
[jsonproperty("user")] public string username { get; set; }
how can values of userinfo? want online value within userinfo object.
there 1 cool feature in vs2013. if re-create json clipboard , in visual studio click edit -> paste special -> paste json classes
generate class construction you. need rename properties if want to. in case modified version of classes be:
public class obj { public string id { get; set; } [jsonproperty("user")] public string username { get; set; } public userinfo userinfo { get; set; } } public class userinfo { public string id { get; set; } public string online { get; set; } }
and can deserialize json string:
var json = @"[{""id"":""255521115"", ""user"":""username"",""userinfo"":{""id"":""158"",""online"":""false""}}]"; var objs = jsonconvert.deserializeobject<ilist<obj>>(json);
c# arrays json serialization
Comments
Post a Comment