我使用下面的代碼來生成JSON數據。如何格式化來自ASP.NET MVC的JSON輸出2
[HttpGet]
public ActionResult MarketList()
{
var mkt = db.GetDailyList();
return Json(mkt, JsonRequestBehavior.AllowGet);
}
現在它以下面的格式返回JSON;
[{"gainers":"CAP","date":"Dec 9 ","Open":30.87,"Close":32.41,"change":1.54},{"gainers":"AP","date":"Dec 9 ","Open":20.00,"Close":21.00,"change":1.00}]
我想要的是以下面的JSON格式返回數據;
[{"dailygainers":{"gainers":"CAP","date":"Dec 9 ","Open":30.87,"Close":32.41,"change":1.54}},{"dailygainers":{"gainers":"AP","date":"Dec 9 ","Open":20.00,"Close":21.00,"change":1.00}}]
我該如何使用MVC 2做到這一點?
謝謝
no joy gnome ..i將代碼更改爲以下內容,結果相同; public JsonResult TopGainers() { IEnumerable list = db.GetTopGainers(); return Json(list,JsonRequestBehavior.AllowGet); } –
femi
2010-12-09 16:51:06