I'm having an issue using an asmx web service to return json to a
jQuery ajax call. If I run the web service stand alone i get a nice
json response as follows:

<string>
{"City":"nyc","Country":"usa","PostalCode":null,"State":null,"Street":null}
</string>

I'm using the DataContractJsonSerializer in .NET to create this json.

When I call this web service from a $.ajax call I can't get at the
values of the json object and i notice in firebug that the response is
now :

{"d":"{\"City\":\"nyc\",\"Country\":\"usa\",\"PostalCode\":null,\"State
\":null,\"Street\":null}"}

Here is my jQuery call:

 $.ajax({
          url: '/webservices/WebService2.asmx/HelloWorldJson',
          dataType: 'json',
          type: 'post',
          error: function(req, textStatus, errorThrown){alert('error
loading response: ' + textStatus);
            },
             beforeSend: function(xhr){
                xhr.setRequestHeader("Content-type","application/json;
charset=utf-8");
            },
          success: function (d) {
          //var customers = eval("(" + d + ")");
          //alert(customers.Country);
          alert(d);
            validateUsername.html(d.country);
          }
        });

but i can never get at the values of the json object that is returned
for some reason. What am i doing wrong?

Reply via email to