开发者

How do I return unnamed JSON string array from asp.net mvc2 json result?

开发者 https://www.devze.com 2023-01-14 20:17 出处:网络
I have the following code: var json = My开发者_如何转开发Object .Select(p => new { id = p.MyObjectId,

I have the following code:

var json = My开发者_如何转开发Object
    .Select(p => new
    {
        id = p.MyObjectId,
        name = p.MyObjectName
    });

return Json(new { json }, JsonRequestBehavior.AllowGet);

This returns a JSON object as follows:

{ json: [ { id: 1, name: "Bob" }, { id: 2, name: "Fred" }, { id: 3, name: "James" } ] }

However, I need it to return the data as:

[ { id: 1, name: "Bob" }, { id: 2, name: "Fred" }, { id: 3, name: "James" } ]

Is this possible using the JSON result?


return Json(json, JsonRequestBehavior.AllowGet);


Try this:

return Json(json, JsonRequestBehavior.AllowGet);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号