不多说直接上!
怎么使用网站有很详细的解释
$.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))) } });