一个非常新的 MVC、JSON 和 LINQ 程序员 - 我创建了一个返回 JSONResult 的 ActionResult:
var formhistory = from p in _formsRepository.ReturnedForms
where p.DateAdded >= DateTime.Now.Date.AddDays(-15) && p.DateAdded <= DateTime.Now.Date
group p by new {p.Centre, p.Form, p.DateAdded}
into g
select new {
g.Key.Centre,
g.Key.Form,
g.Key.DateAdded,
Total = g.Sum(p => p.Quantity)
};
return Json(formhistory, JsonRequestBehavior.AllowGet);
这给了我一个很好的 JSON 结果集,如下所示:
[
{"Centre":"Centre1","Form":"Advice","DateAdded":"\/Date(1331856000000)\/","Total":1067},
{"Centre":"Centre1","Form":"Advice","DateAdded":"\/Date(1332460800000)\/","Total":808},
{"Centre":"Centre1","Form":"Advice","DateAdded":"\/Date(1333062000000)\/","Total":559},
{"Centre":"Centre1","Form":"Advice","DateAdded":"\/Date(1333666800000)\/","Total":1448}
]
我的问题是:我正在尝试操作这个 JSON 字符串,以便“Form”和“Total”的 2 个键/值对只有 1 个,即“Form”:“Total”。
我意识到这可能是一个非常基本的问题,但是谁能指出我正确的方向?(除了门!)