LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   echo javascript json array (https://www.linuxquestions.org/questions/programming-9/echo-javascript-json-array-928733/)

secretlydead 02-10-2012 08:29 PM

echo javascript json array
 
i have a script that's retrieving a json string through ajax.

if i alert(data), i get:
{"account_id":805267,"customer_id":882315,"account_name":"","account_number":"6011xxxxxxxxxxx0000"," enabled":false,"type":"2","bank_name":"","cc_name":"","expiration":"1215","is_savings":false,"date_a dded":"20120210","date_modified":"20120210"}
in a popup window...

but if i
alert(data.account_number), i get
"undefined" in a popup window.

what am i doing wrong?

secretlydead 02-10-2012 09:06 PM

BAH!!! (need to be reviewing my javascript books and notes everyday)

alert( $.parseJSON(data).account_number ); does it.

audriusk 02-11-2012 06:20 AM

You don't need to use $.parseJSON() in AJAX call. Instead you should use $.getJSON() or set dataType to 'json' for $.ajax(). This way jQuery will parse JSON data for you, and you'll be able to use it right away.


All times are GMT -5. The time now is 01:32 AM.