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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -