免费,好用的天气预报API


不多说直接上!

一、API服务,天气API

网站:http://api.help.bj.cn/api/

怎么使用网站有很详细的解释

 $.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)))
                }
            });

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM