Json.NET (Newtonsoft.Json) - Two 'properties' with same name? -
i'm coding in c# .net framework 3.5.
i trying parse json jobject.
the json follows:
{ "tbox": { "name": "smallbox", "length": 1, "width": 1, "height": 2 }, "tbox": { "name": "medbox", "length": 5, "width": 10, "height": 10 }, "tbox": { "name": "largebox", "length": 20, "width": 20, "height": 10 } }
when try parse json jobject, jobject knows largebox. information smallbox , medbox lost. because interpreting "tbox" property, , property being overwritten.
i receiving json service that's coded in delphi. i'm trying create c# proxy service. on delphi-side of things, "tbox" understood type of object being returned. inner properties ("name", "length", "width", "height") understood regular properties.
i can serialize , deserialize custom 'tbox' object has name, length, width, , height properties. that's fine.
what want step through tbox sections in such way extract following 3 json strings.
first:
{ "name": "smallbox", "length": 1, "width": 1, "height": 2 }
second:
{ "name": "medbox" "length": 5, "width": 10, "height": 10 }
third:
{ "name": "largebox" "length": 20, "width": 20, "height": 10 }
once have these strings, can serialize , deserialize heart's content.
i'm finding newtonsoft.json good. don't want go messing other frameworks if can avoid it.
any appreciated.
i have limited input changes can made server.
using newtonsoft.json; using newtonsoft.json.linq; jsontextreader jsonreader = new jsontextreader(reader); jsonreader.read(); while(jsonreader.read()) { if(jsonreader.tokentype == jsontoken.startobject) { jobject tbox = jobject.load(jsonreader); } }
however, note rfc says, "the names within object should unique" if can, recommend format changed.
edit: here's alternate design doesn't have duplicate keys:
[ { "tbox": { "width": 1, "length": 1, "name": "smallbox", "height": 2 } }, { "tbox": { "width": 10, "length": 5, "name": "medbox", "height": 10 } }, { "tbox": { "width": 20, "length": 20, "name": "largebox", "height": 10 } } ]
Comments
Post a Comment