0

I am trying to go to the location json.responseJSON.Sites.LHR and on next iteration json.responseJSON.Sites.NJE so on and so on. notification on the first instance is a string "LHR" and second "NJE". Is this possible?

    for(var notification in json.responseJSON.Sites){
            console.log(json.responseJSON.Sites.notification);
    }

This is my json

{
"Sites": {
    "LHR": 1,
    "NJE": 1,
    "AZS": 1,
    "SGP": 1,
    "OHS": 1,
    "AZP": 1
  }
}
Zac Borders
  • 137
  • 1
  • 3
  • 12

2 Answers2

2

You may have to access it as property access notation (instead of object.property do object['property']) such as:

  responseJSON = {
"Sites": {
    "LHR": 1,
    "NJE": 1,
    "AZS": 1,
    "SGP": 1,
    "OHS": 1,
    "AZP": 1
  }
};

for(var notification in responseJSON.Sites){
    console.log(notification + " : " + responseJSON.Sites[notification]);
    }

Fiddle: https://jsfiddle.net/8fqk8bdw/1/

Jorge Zuverza
  • 885
  • 8
  • 26
1
for(var notification in json.responseJSON.Sites){
        console.log(notification);
}
gbtimmon
  • 4,238
  • 1
  • 21
  • 36
  • No, I want the value of json.responseJSON.Sites.(variable) as in json.responseJSON.Sites.LHR and json.responseJSON.Sites.NJE console.log(notification) gives me "LHR" console.log(json.responseJSON.Sites.LHR) gives me 1 – Zac Borders Apr 15 '15 at 17:52