Guillermo Guerini
Guillermo Guerini

Reputation: 997

How to return a specific Json in ASP.NET MVC?

I'm using this plugin http://devthought.com/projects/jquery/textboxlist/ to autocomplete like Facebook Style. I'm just a bit confuse on how to return the Json result that fits the plugin's need.

The json result must be like this:

[[1, 'John', null, ''],[2,'Mary', null, ''],[3,'Mark', null, '']]

The problem is when I return the result to my View:

return Json(myjSon, JsonRequestBehavior.AllowGet);

This is the result:

"[[1, \u0027John\u0027, null, \u0027\u0027],[2, \u0027Maryn\u0027, null, \u0027\u0027],[3, \u0027Mark\u0027, null, \u0027\u0027]]"

The aposthrophe was converted to \u0027 and its ruining my code. What should I do?

Upvotes: 0

Views: 689

Answers (1)

Dennis C
Dennis C

Reputation: 24747

You just did wrong type of myjSon, which should be an object not string.

var myjSon = new[]{
    new object[]{1,"John", null, ""},
    new object[]{2,"Mary", null, ""},
    new object[]{3,"Mark", null, ""}
};
return Json(myjSon, JsonRequestBehavior.AllowGet); 

EDIT: code corrected according to the comments

Upvotes: 3

Related Questions