romiem
romiem

Reputation: 8950

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

I have the following code:

var json = MyObject
    .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?

Upvotes: 1

Views: 1184

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039100

return Json(json, JsonRequestBehavior.AllowGet);

Upvotes: 3

Adrian Grigore
Adrian Grigore

Reputation: 33318

Try this:

return Json(json, JsonRequestBehavior.AllowGet);

Upvotes: 1

Related Questions