Create json object with multiple array in c# -
i want create json object following format:-
{ "result": [ { "name": "john", "address": "us", }, { "name": "josh", "address": "japan", } ], "error": [ { "message": "error-message" } ], "success": [ { "message": "success-message" } ] }
i have tried following, doesn't me.
dynamic record = new { result = new {name="", address=""}, error = new {message=""}, success = new {message=""} };
update 1:-
here code:- list addresslist = new list();
// loop on items within container , uri. foreach (var item in items) { dynamic record = new { result = new object[] { new {name = item.name, address = item.address} } }; addresslist.add(record); }
result:-
[ { "result": [ { "name": "john", "address": "us" } ] }, { "result": [ { "name": "jack", "address": "ca" } ] } ]
expected json result:-
[{ "result": [{ "name": "john", "address": "us" }] }, { "result": [{ "name": "jack", "address": "ca" }], "error": [{ "message": "error-message" }], "success": [{ "message": "success-message" }] } ]
how update code above expected json result?
you...create arrays. you're not doing that. you're creating individual objects.
something along lines of:
dynamic record = new { result = new object[] { new {name = "john", address = "us"}, new {name = "josh", address = "japan"} }, error = new object[] /*...*/, success = new object[] /*...*/ };
Comments
Post a Comment