PDA

View Full Version : jquery decode json object with double quoted keys


heals1ic
08-05-2009, 03:09 AM
I have a script that outputs a json string via json_encode in PHP. The json string consists of

[{"custId":"2","custName":"John Inc"}]

The PHP script is initiated using

$.getJSON("customer.php", function(data){alert(data + ' ' + data.custName);});

The response is -

[object Object] undefined

Javascript recognises 'data' as an object but I cannot seem to reference the information using json dotted notation.

rnd me
08-05-2009, 03:14 AM
try using alert(data.toSource()); in firefox, and see what data actually is.

heals1ic
08-05-2009, 04:24 AM
Work it out that I had braces surrounding my json string therefore it was being interpreted as array(object).

Fixed it with data[0].custName

Cheers