0

我试图让我的控制器返回一个命名的 JSON 数组。它当前返回格式如下的 JSON:

[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]

但我想要这样

movies:[{"Title":"Star Wars: A New Hope","Year":1977},{"Title":"Star Wars: The Empire Strikes Back","Year":1980},{"Title":"Star Wars: Return of the Jedi","Year":1983}]

这是我的控制器方法:

public JsonResult GetMovies()
{
    var model = _movies;


    return Json(model, JsonRequestBehavior.AllowGet);
}

有任何想法吗?

4

1 回答 1

3

您可以返回匿名 json 对象,例如

 return Json(new {
        movies = model
    } , JsonRequestBehavior.AllowGet);
于 2013-09-20T16:24:56.590 回答