2

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?

1 Answer 1

7

You use alert(jsonObj[0].key1)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.