multiple json objects in in object (json.net) -
is possible format :
"list":{ "one":{ "fieldone":"-----", "fieldtwo":"-----" }, "two":{ "fieldone":"-----", "fieldtwo":"-----" } }
i don't want array [] or names "one" , "two" removes, struggling exact following format.
if put items dictionary instead of list can result want. here example:
class program { static void main(string[] args) { rootobject obj = new rootobject(); obj.items = new dictionary<string, item>(); obj.items.add("one", new item { fieldone = "foo", fieldtwo = "bar" }); obj.items.add("two", new item { fieldone = "fizz", fieldtwo = "bang" }); string json = jsonconvert.serializeobject(obj, formatting.indented); console.writeline(json); } } class rootobject { [jsonproperty("list")] public dictionary<string, item> items { get; set; } } class item { [jsonproperty("fieldone")] public string fieldone { get; set; } [jsonproperty("fieldtwo")] public string fieldtwo { get; set; } }
output:
{ "list": { "one": { "fieldone": "foo", "fieldtwo": "bar" }, "two": { "fieldone": "fizz", "fieldtwo": "bang" } } }
Comments
Post a Comment