Reputation: 1604
I have this javascript object,
console.log(object.response);
console.log(object.response.imageUID);
gives me:
{"id":138,"imageUID":"image-aa0dce87-0261-44ef-8377-d897a996f4b1"}
undefined
What went wrong?
Upvotes: 0
Views: 71
Reputation: 104775
It seemed the issue was that your response was a stringified object - so it probably looked like:
var response = '{"id":138,"imageUID":"image-aa0dce87-0261-44ef-8377-d897a996f4b1"}';
In order to access the properties you must first parse that string into an object:
var responseObj = JSON.parse(response);
Now you can access the properties:
var imageUID = responseObj.imageUID;
Upvotes: 3