Javascript: how to access anonymous object within object?
- by Caballero
I have a string generated by php's json_encode() that looks like this:
[ { "key1":"value1",
"key2":"value2",
"key3":"value3"
},
{ "key1":"value1",
"key2":"value2",
"key3":"value3"
} ]
I use Javascript function to convert the string to Javascript object:
var jsonObj=JSON.parse(string);
How do I access the data inside since the inner objects have no names? I tried something like:
alert(jsonObj.firstChild.key1);
It gives me "undefined". Why is that so?