在下面的代码中,我尝试遍历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>