不多說直接上!
怎么使用網站有很詳細的解釋
$.ajax({ type: "GET", //請求方式 url: "http://api.help.bj.cn/apis/weather/?id=101270101", dataType: "json", data: 'UrlParam', success: function (result) { console.log(result); } });
二、http://wthrcdn.etouch.cn
1.通過名字(json數據/xml數據)
接口:1.http://wthrcdn.etouch.cn/weather_mini?city=北京市;
接口:2.http://wthrcdn.etouch.cn/WeatherApi?city=北京市;
2.通過城市id(json數據)
接口:http://wthrcdn.etouch.cn/weather_mini?citykey=101010100;
$.ajax({ type: "GET", //請求方式 url: "http://wthrcdn.etouch.cn/weather_mini?city=" + '成都', dataType: "json", success: function (result) { // 今日0 明天1 以此2,3,4 let weather = result.data.forecast[0] // for (var i in weather) { // console.log(i, ":", weather[i]); // } for in 不好用 Object.keys(weather).forEach(key => console.log(Object.keys(weather), Object.values(weather))) } });