json对象如何解析?
<a href="#">jsonp</a>
<script src="http://cdn.bootcss.com/jquery/2.0.3/jquery.min.js"></script>
<script>
$('a').click(function(event){
$.getJSON('http://www.pm25.in/api/querys/pm2_5.json?city=zhuhai&token=5j1znBVAsnSf5xQyNQyq&callback=?',
function(data){
var xx = JSON.stringify(data);
alert(xx[0].aqi);
});
event.preventDefault();
});
</script>
弹出:
我想要的结果是:
alert(xx[0]);
弹出{"aqi":35,"area":"珠海","pm2_5":24,"pm2_5_24h":25,"position_name":"吉大","primary_pollutant":null,"quality":"优","station_code":"1367A","time_point":"2014-03-07T08:00:00Z"
或者:
alert(xx[0].aqi);
弹出35
但它弹出undefined了
zzb86
10 years, 8 months ago