我有以下json数据:
series: [{
name: 'Winter 2007-2008',
pointInterval: 24 * 3600 * 1000,
data: [
'[Date.UTC(2013,10,1),1390640]',
'[Date.UTC(2013,10,2),1577267]',
'[Date.UTC(2013,10,3),870361]',
'[Date.UTC(2013,10,4),858799]', .............
我正在使用c#通过字符串操作形成此[Date.UTC(2013,10,4),858799]
数据,以便在高级图表中使用它。
但是没有绘制图表,因为[Date.UTC(2013,10,4),858799]
包含'单引号,当c#字符串被渲染时。
请帮我解决如何从json数据中删除单引号。
答案 0 :(得分:0)
我不确定我理解,但如果你想在将它嵌入JSON字符串之前在C#中评估日期,那么它必须超出双引号。如果你想在JavaScript方面评估它,那么它根本不是真正的 JSON,而是JavaScript,因为JSON中没有函数。 Winter字符串也应该使用嵌入式双引号(如果它是JSON),因为单引号字符串在JSON中无效。
string javaScriptData =
"series: [{" +
"name: 'Winter 2007-2008'," +
"pointInterval: 24 * 3600 * 1000," +
"data: [" +
"[Date.UTC(2013,10,1),1390640]," +
"[Date.UTC(2013,10,2),1577267]," +
"[Date.UTC(2013,10,3),870361]," +
"[Date.UTC(2013,10,4),858799]," +
"]" +
"}]";
OR:
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
string jsonData =
"series: [{" +
"name: \"Winter 2007-2008\"," +
"pointInterval: 24 * 3600 * 1000," +
"data: [" +
"[" + (epoch - new DateTime(2013, 10, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds + ",1390640]," +
"[" + (epoch - new DateTime(2013, 10, 2, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds + ",1577267]," +
"[" + (epoch - new DateTime(2013, 10, 3, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds + ",870361]," +
"[" + (epoch - new DateTime(2013, 10, 4, 0, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds + ",858799]," +
"]" +
"}]";
免责声明:我一生中从未使用过C#或.NET,我只想猜测如何获取时间戳。伊克子>
答案 1 :(得分:0)
在javascript中你可以尝试使用eval()函数,但通常会更好地准备正确的JSON(没有Date.UTC()),因为在json中你不能有函数。