我已經閱讀了其他幾乎確切的問題,但仍然失敗悲慘。我給。 我試過每一個答案,這裏....JQuery,通過JSON循環失敗
這裏是JSON的一個樣本:
[{"count":4,"date":"2010-03-02 09:30:00","id":291,"code":"BPT"},
{"count":4,"date":"2010-03-02 10:30:00","id":292,"code":"BPT"},
{"count":3,"date":"2010-03-02 11:30:00","id":293,"code":"BPT"},
{"count":9,"date":"2010-03-02 12:30:00","id":294,"code":"BPT"},
{"count":8,"date":"2010-03-02 13:30:00","id":295,"code":"BPT"},
{"count":8,"date":"2010-03-02 14:30:00","id":296,"code":"BPT"},
{"count":17,"date":"2010-03-02 15:30:00","id":297,"code":"BPT"}]
這裏是在遍歷數組中的每個哈希得到這個循環當前盲目刺:
<body>
<div id="junk">
</div>
<script type='text/javascript'>
$.getJSON('bpt.json', function(data) {
$.each(data, function() {
$("#junk").html(this.count + "<br />");
});
});
</script>
</body>
我正在使用螢火蟲,我不知道在哪裏看。它只打印第一個值或鍵。 Firebug確實表明json得到正確解析。
Mmh對我來說確實很好。你確定你正確地檢索了JSON嗎?您可以嘗試正常的循環:`for(var i = 0,l = data.length; i 」) ;}`。 `console.log(data.length)`或`console.log(data)`給你什麼? –
2011-01-13 20:31:46
控制檯說405,這正是它應該是。 – Bubnoff 2011-01-13 20:44:42