How to get Ajax.Net PageMethod to return JSON

I use AJAX.Net to call ASP.Net PageMethod, which returns JSON serialized JSON data

{"d":"[{\"Fromaddress\":\"testfrom1@test.com\",\"Toaddress\":\"testto1@test.com\"},{\"Fromaddress\":\"testfrom2@test.com\",\"Toaddress\":\"testto2@test.com\"}]"}

The response header indicates the type of content as

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

However, the data is only 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 returned data as JSON from javascript?

+3
source share
1 answer
var myData = eval('(' + text + ')');

Although this can be a security risk. Instead, you can use a JSON parser such as this available form https://github.com/douglascrockford/JSON-js/blob/master/json2.js

Then you get a type notation:

var myData = JSON.parse(text);

. http://www.json.org/js.html ... , , , .

+4

Source: https://habr.com/ru/post/1728230/


All Articles