Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return JSON structure in ASP MVC

i need to return a JSON with this format:

{"answers": [{"id": "93", "value":"Ahstron"}, 
             {"id"="94", "value"="Sampers"}]}

Im using the return Json() method form ASP MVC Framework, is there a way to specify that this JSOn is a collection of answers like in the sample code? or must i create my own?

with the

return Json(answers);

i just get this:

[{"id": "93", "value":"Ahstron"}, 
{"id"="94", "value"="Sampers"}]}
like image 738
JOBG Avatar asked Jul 11 '09 01:07

JOBG


2 Answers

Try

return Json(new {answers = answers});
like image 141
James S Avatar answered Sep 29 '22 13:09

James S


It almost worked, the correct syntax is:

return Json(new { answers = answers});

Thx a lot =)

like image 44
JOBG Avatar answered Sep 29 '22 13:09

JOBG