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了

json jsonp

zzb86 10 years, 8 months ago

 $('a').click(function(event){
        event.preventDefault();
        $.getJSON('http://www.pm25.in/api/querys/pm2_5.json?city=zhuhai&token=5j1znBVAsnSf5xQyNQyq&callback=?',
            function(data){
            var xx = data[0];
            var json = JSON.stringify(xx);
            alert(xx.aqi);
        });

    });

麦田裸奔者 answered 10 years, 8 months ago

Your Answer