這裏是我的JSON數據如何從JSON數組中檢索數據?
{
"list":[{"rank":"1","fb_id":"12345","score":"3000"},
{"rank":"2","fb_id":"12345","score":"2000"},
{"rank":"3","fb_id":"123456","score":"1000"},
{"rank":"5","fb_id":"123456","score":"2500"}],
"roundscores":[{"score1":"1000","pos1":"3","score2":"2500","pos2":"5"}]
}
從這個數據,我需要使用Java腳本獲得score1
我的JS
$.ajax({
type: "POST",
url: "ajaxClassifica2.jsp",
data: "selectedLevel="+selectedLevel+"&fb_id="+123456,
success: function(data) {
alert(data);
var jsonlist = data.list;
var jsonround = data.roundscores;
alert(jsonlist);
alert(jsonround);
var strBuild = "";
$.each(jsonobj, function(index, names)
{
strBuild ="<ul class=\"livelli\">"
+" <div class=\"social\"> "
+" <a href=\"#\"><img src=\"images/ico_fb.png\"></a>"
+" <a href=\"#\"><img src=\"images/ico_tw.png\"></a>"
+" </div>"
+" <li><strong>Round 1:</strong> " + names.roundscores.score1 + "</li>"
+" <li><strong>Posizione:</strong> " + names.roundscores.pos1 + " </li>"
+" </ul>"
+" <ul class=\"livelli\">"
+" <div class=\"social\"> "
+" <a href=\"#\"><img src=\"images/ico_fb.png\"></a>"
+" <a href=\"#\"><img src=\"images/ico_tw.png\"></a>"
+" </div>"
+" <li><strong>Round 2:</strong> " + names.roundscores.score2 + "</li>"
+" <li><strong>Posizione:</strong> " + names.roundscores.pos2 + "</li>"
+" </ul>";
});
}
});
有幫助你嘗試自己做任何事 – Novocaine
你應該發佈你的代碼,並讓每個人看到你做了什麼。 –
是的,我試過 alert(data); var jsonlist = data.list; var jsonround = data.roundscores; 雖然警報數據我可以看到我的JSON數據 其餘的未定義 – Rohil