I have the following list of search terms in JSON:
http://completion.amazon.com/search/complete?method=completion&q=halo&search-alias=aps&mkt=1
[ "halo",
[ "halo reach",
"halo anniversary",
"halo 4",
"halo 3",
"halo mega bloks",
"halo 2",
"halo sleepsack",
"halo wars",
"halo reach xbox 360",
"halo combat evolved"
],
[ { "nodes" : [
开发者_运维技巧 { "name" : "Video Games",
"alias" : "videogames"
}
]
},
{}, {}, {}, {}, {}, {}, {}, {}, {}
],
[]
]
I am using jQuery to return the results in an autocomplete.
My question is, how would I reference the categories (nodes) in the object? I can reference the terms in the first part like so:
var myQuery = "harry"
, myCount = 0
;
$.ajax({
url : "http://completion.amazon.com/search/complete",
type : "GET",
cache : false,
dataType : "jsonp",
success : function (data) {
$(data[1]).each(function(index) {
alert(data[1][myCount]);
myCount++;
}
);
},
data : {
q : myQuery,
"search-alias" : "aps",
mkt : "1",
callback : '?'
}
});
$(data[2][0].nodes).each(function () { alert(this.name) })
Edit: Fixed by question author. :)
精彩评论