[RESOLVED]Deserialing a JSON object

I’m a newbie who started off using jquery but decided to switch to pure js as much as possible. So I wrote some code to send an ajax POST to my MVC app which returns a JSON object in response using ‘return JSON(data)’

Although in firefox’s debugger I can see all the properties/members/values of the JSON object (even without deserializing it), I can’t seem to access them from code. I then tried deserializing it like this:

var collection = JSON.parse(response)

but I still can’t seem to access the properties. What am I doing wrong?

jal2

var collection = JSON.parse(response)

but I still can’t seem to access the properties. What am I doing wrong?

json.parse is not the one you need.

var collection = new JavaScriptSerializer().Deserialize<List<myModel>>(response);

that should work for you :) just change model ofcourse 

Thanks for helping but i’m not sure we are on the same page. I was referring to client-side deserialization of a json response from the server.  The firefox debugger fully graphs this object but my js code can’t seem to access its members. Any ideas?

But since you mentioned server-side deserialization, do you prefer the JavascriptSerializer? I’ve been using NewtonSoft.Json.Linq to do this on the server side, not sure what library is best.

JSON.parse is working fine, I was making a dumb mistake on my end.

Leave a Reply