我有一个带有日期时间属性的对象列表。我很难以以下形式获取 Json 字符串:
[{"Date":17.08.2013,"Count":8},{"Day":18.08.2013,"Count":10}]
这个
var results = from a in db.Stalkings
group a by new { d = a.Begin.Day }
into g
select new { Day = g.Key.d, Count = g.Count() };
return Json( results, JsonRequestBehavior.AllowGet);
结果为 [{"Day":17,"Count":8},{"Day":18,"Count":10}]。和这个
var results1 = from a in db.Stalkings
group a by EntityFunctions.TruncateTime(a.Begin)
into g
select new { Day = g.Key, Count = g.Count() };
return Json( results, JsonRequestBehavior.AllowGet);
结果 [{"Day":"/Date(1376690400000)/","Count":8},{"Day":"/Date(1376776800000)/","Count":10}]
DateTime.ToString("dd.MM.yyyy") 导致 linq 错误。