I am serializing following class to JSON and returning through API:
public class HighStockChart
{
public string name { get; set; }
public IEnumerable<HighStockChartData> data { get; set; }
}
public class HighStockChartData
{
public DateTime x { get; set; }
public double y { get; set; }
}
Now when I am doing a console log for data , I am getting following format:
{x: "/Date(1519154100000)/", y: 392.61}
{x: "/Date(1519179300000)/", y: 392.732}
{x: "/Date(1519212600000)/", y: 392.732}
{x: "/Date(1519173000000)/", y: 392.733}
{x: "/Date(1519187400000)/", y: 392.757}
{x: "/Date(1519169400000)/", y: 392.761}
But I need the data without /Date. Example format below:
{x: 1519154100000), y: 392.61} {x: 1519179300000), y: 392.732}
Edit:
To build the date String I am doing ,
IEnumerable<HighStockChartData> stockChartXY = tag.Select(t => new HighStockChartData
{
x = DateTime.ParseExact(t.Date, "dd MMM yyyy HH:mm:ss:fff", null),
y = double.Parse(t.Value)
});
HistorianTagDetail historianTagDetailsresult = new HistorianTagDetail
{
Average = average,
HighStockChartData = stockChartXY
};
chartData = ChartHelper.CreateHighStockChart(tagDetails);
return Json(chartData);
By using jQuery to loop through and strip all data will work only if I am using q webClient. I have to find another solution , If I will try to send that as an email , using a service or use the chart in desktop application , then have to strip off the characters using C#.
Can I serialize the dates as Long (we have currently) but without "/Date()"?
Is there any custom attribute to set? Or Can I loop through object after serialization , remove the characters and then return?
ex:
chartData = ChartHelper.CreateHighStockChart(tagDetails);
var jsonData = Json(chartData);
var jDataList = new List<object>();
//Not actual code, just a theory I can think of
foreach(jData in jsonData)
{
//Do something to strip of the brackets
//Add to a list
jDataList.Add(jData);
}
return jDataList;