Daniel Anderson Daniel Anderson - 5 months ago 10
Javascript Question

Can't read JSON reply from web service

So I have a JQuery modal dialog form that takes in a user's registration info, which is then sent as JSON to a web service. The web service processes the registration request and sends back its own JSON. This all works, except I can't figure out how to parse the JSON coming back. Here's the code being called on success of the

$.ajax
method:

success: function (data) {
console.log(data);
console.log(data[0].Reply);
$("#spStatus").css('class',
'textGreen').text(data[0].Reply);


I'm logging the data to the console to inspect what comes back, and this is what I see :

Console messages

I can't seem to figure out how to read the info contained in
data
, and the web service is doing its part to return JSON data. I can't use
JSON.parse
because it's already JSON data that's being returned. I know this has to be something simple. Help?

Answer

The response is a json that has a property d which is a json string and therefore:

success: function (data) {
    var jsonStr = data.d;
    var json = JSON.parse(jsonStr);

    console.log(json.Reply);
}