Javascript: how to access anonymous object within object?

Posted by Caballero on Stack Overflow See other posts from Stack Overflow or by Caballero
Published on 2011-06-24T14:58:59Z Indexed on 2011/06/24 16:22 UTC
Read the original article Hit count: 207

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about JSON