简体   繁体   中英

Javascript: how to access anonymous object within object?

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?

您使用alert(jsonObj[0].key1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM