我在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"
}
]
},
{}, {}, {}, {}, {}, {}, {}, {}, {}
],
[]
]
我正在使用jQuery以自动完成方式返回结果。
我的问题是,如何引用对象中的类别(节点)?我可以像第一部分那样引用术语:
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 : '?'
}
});
答案 0 :(得分:1)
$(data[2][0].nodes).each(function () { alert(this.name) })
编辑:由问题作者修正。 :)