Deserialize complex JSON data in C# -
i'm amateur in c# programming. have json data looks following
{ type: "xxx", width: "xxx", datasource: { "chart": { "caption": "xxx" }, "data": [ {}, {} ] } }
i'm having whole data escaped string. after unescape when i'm using javascriptserializer follows
var data = ser.deserialize<dictionary<string, object>>(chartdata);
i'm able "type", "width" as
data["width"] data["type"]
now have value of "caption". suggestion how that, believe dictionary structure need changed i'm stacked lack of knowledge in c#
if know object's scheme man want create class represents in , deserialize json it:
yourknownclass obj = jsonconvert.deserializeobject<yourknownclass>(json); console.writeline(obj.datasource.chart.caption.value);
another option using dynamic type (there no reason using dynamic object if know schema , can create matching c# class. has performance impact well):
dynamic obj = jsonconvert.deserializeobject<dynamic>(json); console.writeline(obj.datasource.chart.caption.value);
btw, in example i'm using json.net popular library.
Comments
Post a Comment