0
我有下面這種類型的數組。我想用JavaScript來迭代這個數組。這怎麼可能?如何在JQuery中迭代JSON數組
{
"result": true,
"data": [
{
"ID": 1,
"stage_ID": 1,
"badge_type_ID": 1,
"name": "Despertar da Força",
"description": "Fazer a primeira SuperAtividade",
"type": "",
"image_static": "url123.jpg",
"image_animated": "",
"SQL": "",
"published": 1
},
{
"ID": 2,
"stage_ID": 1,
"badge_type_ID": 1,
"name": "Super 3",
"description": "Fazer 3 SuperAtividades",
"type": "",
"image_static": "urlimage123.png",
"image_animated": "",
"SQL": "",
"published": 1
}
等
我嘗試了以下腳本,它返回 「未定義」, 「不確定」。
$.getJSON('https://www.legiaodossuperpoderes.com.br/chronus/api/adm/badges', function(data) {
var output= "<ol>";
for (var i in data) {
output += "<li>" + data[i].ID + "</li>"
}
output+="</ol>";
document.getElementById("placeholder").innerHTML=output;
});
任何解決方案?謝謝!
我想,'function(data)'包含整個對象。你需要參考對象的數據。 –
嘗試使用console.log(data)來檢查從getJSON返回的數據 – Kelvin
嘗試'data = data.data'。而'data [i]'恰好是個錯誤,因爲'i'是數組的非索引值。 – gdlmx