really hope someone can help me with this, it’s driving me mad now…
I have a JSON object, with source:
[{"description":"General Accessories & Parts","id":"1"},{"description":"General Parts","id":"2"},{"description":"Parts","id":"3"}]
It’s an array returned from PHP, it used to look like this:
$array[0]['description']="General Accessories & Parts";
$array[0]['id']="1";
$array[1]['description']="General Parts";
$array[1]['id']="2";
etc...
So, I put the array into my JavaScript code:
obj=eval(ajax.responseText);
Now I need to loop over the description and id for each element in the array, I did try this:
for(var key in obj){
if(!obj[key].hasOwnProperty(key)) continue;
alert(obj[key]['description']);
}
The above code that I tried just echos [object Object],[object Object],[object Object] which is the 3 objects that I know are there.
Use
and not
Quick example: http://jsfiddle.net/W4dwx/