I have a datatable which I am attempting to send to a webpage in the JSON format
{"Heading":[{"value":"someTitle", "id":0, children:[]},...]}
I have attempted to cobble together code in order to do this. The datatable rows contain 3 columns: id, heading and value.
Here is what I have:
JObject ret = JObject.Parse("{ isAdmin: false, data: {} }");
...
var headings = (from row in dt.AsEnumerable()
select row["Heading"].ToString()).Distinct();
//var jsonResults = JObject.Parse(results);
foreach (var heading in headings.ToArray())
{
var dArray =
(from row in dt.AsEnumerable()
where row["Heading"].ToString() == heading
select new { id = row["id"], value = row["reportTitle"] }
).ToArray();
var jArr = new JArray(dArray);
ret["data"][heading] = jArr;
}
The exception I am receiving is
Could not determine JSON object type for type >f__AnonymousType0`2[System.Object,System.Object].
How can I restructure this code to receive the results I need?
dtDataTable. Otherwise it's hard to know if your field names or object structure are correct.