c# Json.net deserializing List<Dictionary<string,object>> -
what proper way deserialize json string? array of dictionaries each dict has "title" , "children" children array of dicts.
i using treeview item source, treeview displays title1 > child1 because assume wrong deserializing i'm doing. try print out child1's first child can't figure out how it. code below has invalid cast exception.
s = @"[{""title"":""title1"",""children"":[{""title"":""child1"",""children"":[{""title"":""grandchild1"",""children"":[{""title"":""huh""}]}] }] }]"; list<dictionary<string, object>> marr = jsonconvert.deserializeobject<list<dictionary<string, object>>>(s); mtreeview.itemssource = marr; list<dictionary<string,object>> cs = (list<dictionary<string,object>>)marr[0]["children"]; debug.writeline(cs[0]["title"]);
https://codetitans.codeplex.com/
codetitans json supports correct parsing of json array/dict of primitives follows:
jsonreader jr = new jsonreader(); ijsonobject json = jr.readasjsonobject(s); debug.writeline(json[0]["children"][0]["title"]);
as far can tell c# library does.
Comments
Post a Comment