views:

49

answers:

1

Hello guys, 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?

+1  A: 

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

Dennis Cheung
Hi Dennis, I tried exactly what you said but I got this error message: No best type found for implicitly-typed array
Guillermo Guerini
It complains about the new[] inside the main new[] { .... }; Can you help me with that please? Thanks!
Guillermo Guerini
@Guillermo change the inner `new []` to `new object[]` and that should work. The compiler is complaining because you have strings and ints in the array and it doesn't know which type to use
amarsuperstar