I EDITED THE SOLUTION BELOW THE QUESTION !!!
I have read like 30 similar articles on this, but nothing quite hits the spot.
My scenario: in order to feed a charting library (highcharts/highstock) with data in ASP.NET I manually created the basic classes for such a graph. This is due to the fact that all the wrapper projects work for highcharts but NOT for highstock. However, highstock requires a HTML script block like this (working):
<script>
$('#container2').highcharts('StockChart',
{
"title": {
"text": "Graph_Title_string"
},
"yAxis": {
"title": {
"text": "YAxis_Title_string"
},
"height": 200,
"lineWidth": 2,
"top": 80
},
"series": [
{
"type": "line",
"name": "Testdata",
"data": [[Date.UTC(2014, 3, 8, 0, 0), 3], [Date.UTC(2014, 3, 9, 0, 0), 2], [Date.UTC(2014, 3, 10, 0, 0), 4], [Date.UTC(2014, 3, 11, 0, 0), 4], [Date.UTC(2014, 3, 12, 0, 0), 3], [Date.UTC(2014, 3, 13, 0, 0), 4], [Date.UTC(2014, 3, 14, 0, 0), 2], [Date.UTC(2014, 3, 15, 0, 0), 1], [Date.UTC(2014, 3, 16, 0, 0), 4], [Date.UTC(2014, 3, 17, 0, 0), 0]]
}]
});
I created the c# classes and their properties, as for example:
public class Series
{
public string type { get; set; }
public string name { get; set; }
public object data { get; set; }
}
Later on I use JsonConvert.SerializeObject to serialize my chart-object (with instanced classes title, yAxis, series etc within), which results in following output:
{
"title": {
"text": "Graph_Title_string"
},
"yAxis": {
"title": {
"text": "YAxis_Title_string"
},
"height": 200,
"lineWidth": 2,
"top": 0
},
"series": [
{
"type": "line",
"name": "Testdata",
"data": "[[Date.UTC(2014, 3, 8, 0, 0), 3],[Date.UTC(2014, 3, 9, 0, 0), 2],[Date.UTC(2014, 3, 10, 0, 0), 0],[Date.UTC(2014, 3, 11, 0, 0), 4],[Date.UTC(2014, 3, 12, 0, 0), 4],[Date.UTC(2014, 3, 13, 0, 0), 2],[Date.UTC(2014, 3, 14, 0, 0), 1],[Date.UTC(2014, 3, 15, 0, 0), 1],[Date.UTC(2014, 3, 16, 0, 0), 0],[Date.UTC(2014, 3, 17, 0, 0), 3]]"
}
]
}
So the problem is: the value of series->data is enclosed in quotes. As highstock obviously requires an object array as data ([[DateTime, value],[DateTime, value],...etc]), the chart is not rendered unless I remove these quotes around the array.
When the array was "pure" integer there would be no quotes (I guess), but as my points need to be DateTime/value I need an array of objects.
Therefore the question: how can I force my JSON serializer to NOT enclose my value of an object array in quotes?
Maybe this is trivial and simple, and I was looking to far. As said, I've read lots of articles on similar problems, but nothing worked for me. Any help highly appreciated!
SOLUTION:
the data-array in my series-node is int/double - DATE.UTC(2014, 3, 8, 0, 0) doesn't return a DateTime but a NUMBER (reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC)
Therefore defining a double array in my behind-class will result in the desired output format (as seen in the great suggestion below by craig and also the marked answer) without the quotation marks.
Code (reference: http://forums.asp.net/post/1463013.aspx ... however, slightly modified) for converting c# DateTime to the required milliseconds-timestamp:
public double MilliTimeStamp(DateTime d2)
{
DateTime d1 = new DateTime(1970, 1, 1);
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
return ts.TotalMilliseconds;
}