【发布时间】:2015-01-30 12:08:41
【问题描述】:
在 MVC JsonResult 操作中,我将数据绑定到字典并通过 JSON 返回。它以不同于我需要的形式为我提供数据。
我的代码:
var query = obj.Where(x => x.Date > new DateTime(01 / 01 / 2000)
&& x.Date <= Convert.ToDateTime(shortDate))
.GroupBy(x => x.Date)
.Select(x => new { LogDate = x.Key, Count = x.Count() });
Dictionary<string, int> openWith = new Dictionary<string, int>();
foreach (var output in query)
{
openWith.Add(output.LogDate.ToShortDateString(), output.Count);
}
string letter = "letter";
var chartsdata = openWith;
return Json(chartsdata,letter, JsonRequestBehavior.AllowGet);
JSON 数据的格式为:
var data1 = {
"01/28/2015": 1,
"01/30/2015": 6,
"01/29/2015": 1,
"01/22/2015": 3,
"01/20/2015": 1,
"01/10/2015": 5 }
要绘制图表,我需要表格中的数据:
var data1 = [
[gd(2015, 1, 28), 1],
[gd(2015, 1, 30), 6],
[gd(2015, 1, 29), 1],
[gd(2015, 1, 22), 3],
[gd(2015, 1, 20), 1],
[gd(2015, 1, 10), 5] ]
如果有人知道,请告诉我:如何更改数据格式?
【问题讨论】:
标签: c# json dictionary flot