We currently use Newtonsoft.Json
to convert a datatable to a json
stream.
If my datatable includes the following:
Name Sales
Joe 10
Mary 20
then the following code will return [{"Name": "Joe", "Sales":10},{"Name": "Mary", "Sales":20}]
which is great:
string callback = JsonConvert.SerializeObject(table);
byte[] resultBytes = Encoding.UTF8.GetBytes(callback);
return new System.IO.MemoryStream(resultBytes);
But there are times that I need a more complex json
stream. Something like this:
{ "map": "USA", "areas":[{"Name": "Joe", "Sales":10},{"Name": "Mary", "Sales":20}]}
The json now includes an extra tuple { "map": "USA", "areas":
, and an additional {}
.
What does my datatable need to include to get that type of json stream? And what does the C# need to look like?