I have a problem with javascript, im calling an ajax method that returns this string:
{
"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 assing the content in this way:
xhr.onreadystatechange = ensureReadiness;
....
responseText = xhr.responseText;
If i try to parse it on javascript with:
response = JSON.parse(responseText);
if I acces a property such response.ObjectResponse.Operation I do get the right content.. but when I try to access the List it allways brakes
and if I try the same String but instead of calling the service I assign the content to a var it works I do can access the List
var myTemporalString ='{"ObjectResponse":{"Operation":"OK","Response":"SUCCESS","Message":"List of Keys Found","List":...';
response.JSON.parse(myTemporalString);
Any suggestion why this could be happening?
You can try this way,