从MVC控制器返回Json数据

use*_*211 3 asp.net-mvc json

   public ActionResult About()
    {
        List<Stores> listStores = new List<Stores>();
        listStores = this.GetResults("param");
        return Json(listStores, "Stores", JsonRequestBehavior.AllowGet);
    }
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,我可以得到以下结果

[{"id":"1","name":"Store1","cust_name":"custname1","telephone":"1233455555","email":"abc@ac.com","geo":{"latitude":"12.9876","longitude":"122.376237"}},

{"id":"2","name":"Store2","cust_name":"custname2","telephone":"1556454","email":"nfnf@ac.com","geo":{"latitude":"12.9876","longitude":"122.376237"}},
Run Code Online (Sandbox Code Playgroud)

我怎样才能以下面的格式得到结果?

{

"stores" : [
{"id":"1","name":"Store1","cust_name":"custname1","telephone":"1233455555","email":"abc@ac.com",
"geo":{"latitude":"12.9876","longitude":"122.376237"}},

{"id":"2","name":"Store2","cust_name":"custname2","telephone":"1556454","email":"nfnf@ac.com","geo":{"latitude":"12.9876","longitude":"122.376237"}} ] 
}
Run Code Online (Sandbox Code Playgroud)

我想stores在数据的开头有.

请帮助我这方面.

Ric*_*lly 5

您需要创建一个对象,该对象包含名为stores的属性中的存储:

public ActionResult About()
{
    var result = new { stores = this.GetResults("param") };
    return Json(result, "Stores", JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

我在这里使用匿名类型来简化,如果在多个地方需要这种结果类型,你可以考虑为它创建一个"适当的"类.