My JavaScript code is giving me trouble. I am using an ajax method that returns a JSON string like this:
{
"ObjectResponse": {
"Operation": "OK",
"Response": "SUCCESS",
"Message": "List of AAA Found",
"List": [
{
"keySource": "gat\/images\/images_set\/apple.jpg",
"idSiteKey": "1",
"text": "Apple"
},
{
"keySource": "gat\/images\/images_set\/cat.jpg",
"idSiteKey": "2",
"text": "Cat"
},
{
"keySource": "gat\/images\/images_set\/coffee.jpg",
"idSiteKey": "3",
"text": "Coffee"
},
{
"keySource": "gat\/images\/images_set\/dog.jpg",
"idSiteKey": "4",
"text": "Dog"
},
{
"keySource": "gat\/images\/images_set\/horse.jpg",
"idSiteKey": "5",
"text": "Horse"
},
{
"keySource": "gat\/images\/images_set\/police.jpg",
"idSiteKey": "6",
"text": "Police"
},
{
"keySource": "gat\/images\/images_set\/tree.jpg",
"idSiteKey": "7",
"text": "Tree"
}
]
}
}
I am trying to assign the content like this:
xhr.onreadystatechange = ensureReadiness;
....
responseText = xhr.responseText;
When I attempt to parse it in JavaScript with:
response = JSON.parse(responseText);
If I try to access a property like
response.ObjectResponse.Operation
, I get the correct content.. but accessing the List always breaks.
Interestingly, if I use the same JSON string and directly assign it to a variable without calling the service, I can access the List successfully.
var myTemporalString ='{"ObjectResponse":{"Operation":"OK","Response":"SUCCESS","Message":"List of Keys Found","List":...';
response.JSON.parse(myTemporalString);
Any suggestions on why this might be happening?