A common problem with ajax requests is that your response comes in a string. And a json in text is not particularly useful.

There is a small trick to restore your json to its original glory: eval( “(“+jsonString+”)”);

There you go!

2 thoughts on “Tips #3: Use eval() when you receive a json in a string variable

  1. This is really not a great idea since eval is so dangerous to use that way. You should really offer better was to do it. JSON.parse in newer browsers. I usually use the easy to find parseJSON.js and then wrap the call to test for the JSON object before calling the non native method.

Comments are closed.