I am tring to create nested json string here is my json string below,
[
{
'CompanyID':'1',
'Name':'Company1',
'DepartmentName':'Executive General and Administration',
'ModifiedDate':'2005-06-01 00:00:00.000',
},
{
'CompanyID':'2',
'Name':'Company2',
'DepartmentName':'Executive General and Administration',
'ModifiedDate':'2005-06-01 00:00:00.000',
},
{
'CompanyID':'3',
'Name':'Company3',
'DepartmentName':'Executive General and Administration',
'ModifiedDate':'2005-06-01 00:00:00.000',
}
]
and i want result like this
[
{
'CompanyID':'1',
'Name':'Company1',
department":{
'DepartmentName': 'Dpt1'
}
}
]
I want company wise department for this json string... I used Jarray but failed to do so...
my code:
string jsonCompany = "[{'CompanyID' : '1','Name' : 'Company1','DepartmentName' : 'D1','ModifiedDate' : '2005-06-01 00:00:00.000',},{'CompanyID' : '2','Name' : 'Company2','DepartmentName' : 'D2','ModifiedDate' : '2005-06-01 00:00:00.000',},{'CompanyID' : '1','Name' : 'Company3','DepartmentName' : 'D3','ModifiedDate' : '2005-06-01 00:00:00.000',}]";
string jsonDept = "[{'DepartmentID' : '91','Name' : 'Executive84','GroupName' : 'Executive General and Administration','ModifiedDate' : '2005-06-01 00:00:00.000',},{'DepartmentID' : '92','Name' : 'Executive85','GroupName' : 'Executive General and Administration','ModifiedDate' : '2005-06-01 00:00:00.000',},{'DepartmentID' : '93','Name' : 'Executive86','GroupName' : 'Executive General and Administration','ModifiedDate' : '2005-06-01 00:00:00.000',}]";
object dynJsonCmp = JsonConvert.DeserializeObject(jsonCompany);
dynamic dynJsonDept = JsonConvert.DeserializeObject(jsonDept);