views:

325

answers:

1

I am using an AJAX.Net to call an ASP.Net PageMethod, which returns JSON serialized JSON data

{"d":"[{\"Fromaddress\":\"[email protected]\",\"Toaddress\":\"[email protected]\"},{\"Fromaddress\":\"[email protected]\",\"Toaddress\":\"[email protected]\"}]"}

The Response Header states the content type as

"Content-Type   application/json; charset=utf-8"

However, the data is just available as a string, and does not seem to be available as JSON data from javascript. What do I need to do to work with the returned data as JSON from javascript?

+3  A: 
var myData = eval('(' + text + ')');

Although this can be a security risk. Instead you might want to use a JSON parser, such as this one available form http://www.json.org/json2.js

Then you get notation like:

var myData = JSON.parse(text);

See http://www.json.org/js.html for more info on this particular parser... I believe there are others to choose from, and that they work very similarly.

SoloBold
Also - this was a useful link about how to user browsers inbuilt JSON parsing: http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/
James