how to join two different JSON into single JSON in C# -
my first json follows
[{ "userid": 4, "firstname": "rupesh", "lastname": "abc", "email": "abc@gmail.com", "gender": "male" }]
my second json follows
[{ "accountid": 2, "accountname": "rupeshinfo", "accountdomain": null, "roleid": 1, "userid": 4 }, { "accountid": 3, "accountname": "rameshinfo", "accountdomain": null, "roleid": 2, "userid": 4 }]
the result must be
{ "userdetails": [{ "userid": 4, "firstname": "rupesh", "lastname": "abc", "email": "abc@gmail.com", "gender": "male" }], "accountdetails": [{ "accountid": 2, "accountname": "rupeshinfo", "accountdomain": null, "roleid": 1, "userid": 4 }, { "accountid": 3, "accountname": "rameshinfo", "accountdomain": null, "roleid": 2, "userid": 4 }] }
if don't want mess string inserts can go (and recommend so) using dynamic objects:
var javascriptserializer = new javascriptserializer(); var userdetails = javascriptserializer.deserializeobject(json1); var accountdetails = javascriptserializer.deserializeobject(json2); var resultjson = javascriptserializer.serialize(new {userdetails = userdetails, accountdetails = accountdetails});
Comments
Post a Comment