返回的json数据
{"HeWeather5": [
{"aqi": {"city": {"aqi": "52","pm10": "54","pm25": "36","qlty": "良"}
},"basic": {"city": "平顶山","cnty": "中国","id": "CN101180501","lat": "33.73524094","lon": "113.30771637","update": {"loc": "2017-05-15 15:53","utc": "2017-05-15 07:53"}
},"daily_forecast": [
{"astro": {"mr": "22:57","ms": "08:40","sr": "05:27","ss": "19:20"},"cond": {"code_d": "300","code_n": "100","txt_d": "阵雨","txt_n": "晴"},"date": "2017-05-15","hum": "64","pcpn": "0.1","pop": "31","pres": "1015","tmp": {"max": "23","min": "13"},"uv": "7","vis": "19","wind": {"deg": "27","dir": "东北风","sc": "3-4","spd": "13"}
},
{"astro": {"mr": "23:41","ms": "09:31","sr": "05:26","ss": "19:21"},"cond": {"code_d": "100","code_n": "100","txt_d": "晴","txt_n": "晴"},"date": "2017-05-16","hum": "53","pcpn": "0.0","pop": "0","pres": "1011","tmp": {"max": "30","min": "18"},"uv": "8","vis": "20","wind": {"deg": "233","dir": "东南风","sc": "4-5","spd": "23"}
},
{"astro": {"mr": "null","ms": "10:23","sr": "05:25","ss": "19:22"},"cond": {"code_d": "100","code_n": "100","txt_d": "晴","txt_n": "晴"},"date": "2017-05-17","hum": "47","pcpn": "0.0","pop": "0","pres": "1006","tmp": {"max": "34","min": "19"},"uv": "8","vis": "20","wind": {"deg": "224","dir": "南风","sc": "3-4","spd": "13"}
}
],"hourly_forecast": [
{"cond": {"code": "101","txt": "多云"},"date": "2017-05-15 16:00","hum": "48","pop": "0","pres": "1014","tmp": "22","wind": {"deg": "24","dir": "东北风","sc": "微风","spd": "16"}
},
{"cond": {"code": "103","txt": "晴间多云"},"date": "2017-05-15 19:00","hum": "54","pop": "0","pres": "1014","tmp": "20","wind": {"deg": "52","dir": "东北风","sc": "微风","spd": "11"}
},
{"cond": {"code": "103","txt": "晴间多云"},"date": "2017-05-15 22:00","hum": "66","pop": "0","pres": "1015","tmp": "18","wind": {"deg": "39","dir": "东北风","sc": "微风","spd": "6"}
}
],"now": {"cond": {"code": "101","txt": "多云"},"fl": "18","hum": "61","pcpn": "0","pres": "1017","tmp": "19","vis": "7","wind": {"deg": "40","dir": "北风","sc": "4-5","spd": "28"}
},"status": "ok","suggestion": {"air": {"brf": "中","txt": "气象条件对空气污染物稀释、扩散和清除无明显影响,易感人群应适当减少室外活动时间。"},"comf": {"brf": "舒适","txt": "白天不太热也不太冷,风力不大,相信您在这样的天气条件下,应会感到比较清爽和舒适。"},"cw": {"brf": "不宜","txt": "不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。"},"drsg": {"brf": "较舒适","txt": "建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。"},"flu": {"brf": "较易发","txt": "昼夜温差较大,较易发生感冒,请适当增减衣服。体质较弱的朋友请注意防护。"},"sport": {"brf": "较不宜","txt": "有降水,且风力较强,推荐您在室内进行低强度运动;若坚持户外运动,请选择避雨防风的地点。"},"trav": {"brf": "适宜","txt": "有降水,温度适宜,在细雨中游玩别有一番情调,可不要错过机会呦!但记得出门要携带雨具。"},"uv": {"brf": "弱","txt": "紫外线强度较弱,建议出门前涂擦SPF在12-15之间、PA+的防晒护肤品。"}
}
}
]
}
var url = "https://free-api.heweather.com/v5/weather?city="+citytq+"&key=d7bd43af19c64994b62fc643e5d75272";
$.getJSON(url,function(data){
alert(data.HeWeather5[0].aqi.city.aqi)
});
或者
$.ajax({
type : "get",
url : url,
dataType : "json",
// scriptCharset : "gbk",
success : function(data) {
// var HeWeather5=JSON.parse(data);//因为传回来的是json数据对象,所以这个json数据解析会出错
alert(data.HeWeather5[0].aqi.city.aqi);
或者alert(data[‘HeWeather5‘][0][‘aqi‘][‘city‘][‘aqi‘]);
//$(‘#weather‘).html(tq);
}
});