
Simply looks in above picture for expressive structure of Array in Object.
If structure wrapped by {} that indicates its a Object So you can access property by . which contains property name and its value (any type of value)
If wrapped by [] that indicate it is Array so you can access inner value by [<index>]. it contains set of value(any type of value) only.
Here var json is object because it wrapped by {} inner level property "responseHeader","spellcheck" are object because it's structure wrapped by {}, BUT you look into sub level "suggestions" is wrapped by [] so its array.
If you want to access value of zkConnected so your code should be
console.log(json.responseHeader.zkConnected);
If you want to access value of numFound so your code should be
console.log(json.spellcheck.suggestions[1].numFound);
Because in suggestions is array and have two value one is string "a" at index 0, and another is object at index 1.
If you want to access "e" of suggestion so your code should be
console.log(json.spellcheck.suggestions.suggestion[4]);
Because under suggestions, suggestion is array and e stands on 5th position so you can access it by index 4(position-1)
var json = {
"responseHeader": {
"zkConnected": true,
"status": 0,
"QTime": 0
},
"spellcheck": {
"suggestions": ["a", {
"numFound": 6,
"startOffset": 0,
"endOffset": 1,
"suggestion": ["a", "b", "c", "d", "e", "f"]
}]
}
}
json.spellcheck.suggestions?json.spellcheck.suggestions[1].suggestion. JSON is just a combination of arrays and objects.var number = 'Red';.