深入研究JSON

I am getting back the following dataset from my server

{"success":"y","carrier":"Verizon Wireless","isMobile":"true"}

and when I try to drill into the json result from my ajax function

$.ajax(
{
    url: 'php/lookup.php',
    data: 'number='+encodeURIComponent(num),
    datatype: 'json',
    type: 'get',
    success: function (j) 
    {

        alert(j);
        alert(j.carrier);

    }

I am able to alert the entire JSON string when I do alert(j), but when I do alert(j.carrier) I get an undefined.

Can someone shed some light on this?

Thanks!

Use dataType: 'json' instead of datatype: 'json'.

JavaScript is case-sensitive, and jQuery.ajax requires does not recognise lowercase datatype.

datatype should be dataType (note the capital T).

Try changing datatype to dataType. You could also have your server code send a header of Content-type: application/json, but fixing the parameter should probably be enough.