1

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?

2 Answers 2

3
return Json(json, JsonRequestBehavior.AllowGet);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

return Json(json, JsonRequestBehavior.AllowGet);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.