在下面的代碼中,我嘗試遍歷JSON對象字符串。但是,我沒有得到所需的輸出。我的網頁上輸出看起來是這樣的: -通過遍歷JSON對象迭代的問題
+ item.temperature ++ item.temperature ++ item.temperature ++ item.temperature +
輸出溫度警報效果很好。我嘗試通過遍歷JSON對象字符串來訪問值的部分似乎不起作用。有人能幫我解決這個問題嗎?
代碼
<body>
<script>
$.getJSON('http://ws.geonames.org/weatherJSON?north=90&south=-9.9&east=-22.4&west=55.2',
function(data) {
$.each(data.weatherObservations, function(i,item){
$("body").append("+item.temperature+");
if (i == 3) return false;
});
alert(data.weatherObservations[0].temperature);
});
</script>
</body>