Possible Duplicate:
How to parse JSON in JavaScript
I am pulling a multi-object associative array out of PHP. An example is below:
$displayArray[] = array("Name"=>"Joe", "Important"=>"1", "Group"=>"Family");
$displayArray[] = array("Name"=>"Jane", "Important"=>"0", "Group"=>"Family");
echo json_encode($displayArray);
Using AJAX, the returned JSON string is so:
[{"Name":"Joe","Important":"1","Group":"Family"},{"Name":"Jane","Important":"0","Group":"Family"}]
I would like to convert this JSON data into a Javascript array. Help appreciated.
Looks like you’re using jQuery. The return from .ajax() isn’t the object you’re echo back to the browser via PHP. Instead, you can access the returned data using the success callback, e.g.:
You can then parse myData like a standard javascript object, e.g.:
I think most people tend to write their code to handle the returned object in the success function itself, e.g.: