How can i store a JSON object in an attribute of JSON object, i mean the value of an attribute of JSON object is another JSON object. I have a DataTable dt, i read data from DataBase and store it in this DataTable.
using (var da = new SqlDataAdapter(command))
{
command.CommandType = CommandType.StoredProcedure;
da.Fill(dt);
}
Now, i add a column to this DataTable
dt.Columns.Add("attributes");
Now, i create a JObject and store its value in the "attributes" column for each row of DataTable
dynamic attributeValue = new JObject();
attributeValue.type = "Stage_FF_Hot_Alerts__c";
foreach (DataRow d in dt.Rows)
{
d["attributes"] = attributeValue;
}
Now, i Serialize this DataTable
string JSONresult = JsonConvert.SerializeObject(dt);
The result which i get is
{
"attributes" : "{"type" : "Stage_FF_Hot_Alerts__c"}",
"Address__c" : "Street",
"AgentID__c" : "123456",
"Alert_Status__c" : "Closed",
"BusinessUnit__c" : "INFINITI",
"Case_Type__c" : "INFINITI Service",
"City__c" : "City",
"ContactId__c" : "10951",
"DayTimePhone__c" : "123456789",
"DealerCode__c" : "72067",
"DealerName__c" : "Infiniti Of Kansas City",
"EmailAddress__c" : "[email protected]",
"EveningPhone__c" : "123456789",
"FirstName__c" : "CustomerFirstName",
"HotAlertType__c" : "Hot Alert",
"LastName__c" : "CustomerSurname",
"NPS_Score_1__c" : "0",
"V01_Alert_Trigger__c" : "Which of the following best describes your overall service experience?",
"Field_Open_Date__c" : "2018-08-05"
}
while the result which i want is
{
"attributes" : {"type" : "Stage_FF_Hot_Alerts__c"},
"Address__c" : "Street",
"AgentID__c" : "123456",
"Alert_Status__c" : "Closed",
"BusinessUnit__c" : "INFINITI",
"Case_Type__c" : "INFINITI Service",
"City__c" : "City",
"ContactId__c" : "10951",
"DayTimePhone__c" : "123456789",
"DealerCode__c" : "72067",
"DealerName__c" : "Infiniti Of Kansas City",
"EmailAddress__c" : "[email protected]",
"EveningPhone__c" : "123456789",
"FirstName__c" : "CustomerFirstName",
"HotAlertType__c" : "Hot Alert",
"LastName__c" : "CustomerSurname",
"NPS_Score_1__c" : "0",
"V01_Alert_Trigger__c" : "Which of the following best describes your overall service experience?",
"Field_Open_Date__c" : "2018-08-05"
}