I have a JSON response as follows in the form of [object Object] under variable data :
{
"name": "John Johnson",
"street": "Oslo West 16",
"posts": {
"id1": "121331",
"id2": "9089085",
"id3": "3424234"
}
}
data equals [object Object] and
data.posts equals {"id1":"121331","id2":"9089085","id3":"3424234"}
How to simply access id3 value because it does not equal data.posts.id3 nor equals data.posts['id3'] ?
JSON.stringify(data) gives \n and \ between the objects inside posts Only? could this be the problem?:
{
"name": "John Johnson",
"street": "Oslo West 16",
"posts": { \n \"id1\": \"121331\", \n \"id2\": \"9089085\", \n \"id3\": \"3424234\"
}
}
data.postsis actually a string. What doesJSON.parse(data.posts).id3give you?json_encode) to generate the JSON for you. Otherwise you could end up with a problem similar to what you are seeing here.