function setup() {
loadJSON("https://api.pandascore.co/lol/champions.json?token=<token>", gotData);
}
function gotData(data) {
var x = data.i.teams.name
for (var i = 0; i < data.length; i++) {
if (x == "Neon Esports") {
document.write(data.i.name);
}
document.write(data.i.teams.name);
}
}
但是我只是遇到这个错误 无法读取未定义的属性“团队”
答案 0 :(得分:0)
尝试一下:
function gotData(data) {
data = JSON.parse(data); // let JS know you're dealing with JSON
for (var i = 0; i < data.length; i++) {
var x = data[i].teams[0].name; // we get the name while fetching the data
if (x == "Neon Esports") {
document.write(x);
}
document.write(data[i].teams[0].name);
}
}
希望我进一步推动了你。