I have a php multidimensional array populated from a table using the following code:
<?php starts
$array = array();
$i = 0;
while($row = mysql_fetch_array($result))
{
$array[$i] = array("handle" => $row['handle'],"firstname" => $row['first_name'],"lastname" => $row['last_name']);
$i++;
}
echo json_encode(json_encode($array));
?> php ends
this is called by .post from jQuery and when I alert() the data returned I get the following output:
[
{"handle":"admin","firstname":"admin","lastname":"admin"},
{"handle":"ms","firstname":"ms","lastname":"ms"},
{"handle":"op","firstname":"op","lastname":"op"},
{"handle":"ui","firstname":"ui","lastname":"ui"}
]
the Jquery code I use to extract the php array is:
$.post("test1.php","",
function(data){
var obj = $.parseJSON(data);
alert(obj);
var obj2 = $.parseJSON(obj);
alert(obj2);
alert(obj2[1]);
var result = eval(data);
alert(result[0][0]);
},"html");
alert(obj) gives me the output specified. alert(obj2) gives me:
[object Object],[object Object],[object Object],[object Object]
alert(obj2[1]) gives me:
[object Object]
How do I get at the data in this???