I’m using JSON.Net for serializeation.
I need my data to look like this json object:
{
name: "0.8C",
data: [["10-10-2011", 10], ["10-11-2011", 20], ["10-12-2011", 25], ["10-13-2011", 40], ["10-14-2011", 50], ["10-15-2011", 60], ["10-16-2011", 70], ["10-17-2011", 80], ["10-18-2011", 100]]
}
So I modeled my object like this:
public class ScatterLineChartSeriesModel
{
public IList<IDictionary<DateTime, double>> Data { get; set; }
}
However this serializes the Data property like so:
[
{
"01/31/1966 00:00:00": 1008.795324292118,
"02/28/1966 00:00:00": 992.18823885452684,
"03/31/1966 00:00:00": 967.39109875352267,
"04/30/1966 00:00:00": 985.79507840133135
}
]
How can I structure my C# Data Property to serialize directly to the desired structure ?
It would have to be like this (add Name property, and make the IDictionary an IList):
Your desired output [“10-10-2011”, 10] is a heterogeneous array, so the source has to be a list of objects.
The other option (seems like a better option to me, if in fact your schema is as fixed as your example suggests) would be make the date and number into properties:
Like this: