天气Api接口

接口请求格式如下:

http://cdn.weather.hao.360.cn/sed_api_weather_info.php?app=360chrome&code=【地区编码】&_jsonp=【jsonp回调函数】

其中的 地区编码 与中国天气网的地区编码是一样的。如果不设置这个参数,则默认显示本地的天气状况。

简易的调用示例源码如下:(请自行进行界面美化)

<!DOCTYPE html>  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
<title>天气接口使用示例</title>  
<style>  
body {  
    font-family: microsoft yahei;  
}  
</style>  
<script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>  
</head>  
<body>  
  
<div id="output"></div>  
  
<script type="text/javascript" charset="utf-8">  
      
    $.ajax({  
        type: "GET",   
        url: "http://cdn.weather.hao.360.cn/sed_api_weather_info.php?app=360chrome",  
        dataType : "jsonp",  
        jsonp: "_jsonp",//参数名  
        success: function(jsonData){  
            var html;  
            html = '数据更新时间:' + jsonData.pubdate + ' ' + jsonData.pubtime + '<br>';  
              
            html += '地区:' + jsonData.area[0][0] + ' ' + jsonData.area[1][0] + ' ' + jsonData.area[2][0] + '<br>';  
            html += '天气情况:<br>';  
              
            for(var i =0; i<jsonData.weather.length; i++) {  
                html += jsonData.weather[i].date + '<br>';  
                  
                if(jsonData.weather[i].info.dawn !== undefined) {  
                    html += '早晨天气:' + jsonData.weather[i].info.dawn[1] +   
                    ' 气温:' + jsonData.weather[i].info.dawn[0] + '~' + jsonData.weather[i].info.dawn[2] + '℃ ' +  
                    jsonData.weather[i].info.dawn[3] +' '+ jsonData.weather[i].info.dawn[4] + '<br>';  
                }  
                  
                if(jsonData.weather[i].info.day !== undefined) {  
                    html += '白天天气:' + jsonData.weather[i].info.day[1] +   
                    ' 气温:' + jsonData.weather[i].info.day[0] + '~' + jsonData.weather[i].info.day[2] + '℃ ' +  
                    jsonData.weather[i].info.day[3] +' '+ jsonData.weather[i].info.day[4] + '<br>';  
                }  
                  
                if(jsonData.weather[i].info.night !== undefined) {  
                    html += '夜间天气:' + jsonData.weather[i].info.night[1] +   
                    ' 气温:' + jsonData.weather[i].info.night[0] + '~' + jsonData.weather[i].info.night[2] + '℃ ' +  
                    jsonData.weather[i].info.night[3] +' '+ jsonData.weather[i].info.night[4] + '<br>';  
                }  
                html += '<br>';  
            }  
              
            html += '穿衣:<br>';  
            html += '【' + jsonData.life.info.chuanyi[0] + '】 ' + jsonData.life.info.chuanyi[1] + '<br><br>';  
              
            html += '感冒:<br>';  
            html += '【' + jsonData.life.info.ganmao[0] + '】 ' + jsonData.life.info.ganmao[1] + '<br><br>';  
              
            html += '空调:<br>';  
            html += '【' + jsonData.life.info.kongtiao[0] + '】 ' + jsonData.life.info.kongtiao[1] + '<br><br>';  
              
            html += '污染:<br>';  
            html += '【' + jsonData.life.info.wuran[0] + '】 ' + jsonData.life.info.wuran[1] + '<br><br>';  
              
            html += '洗车:<br>';  
            html += '【' + jsonData.life.info.xiche[0] + '】 ' + jsonData.life.info.xiche[1] + '<br><br>';  
              
            html += '运动:<br>';  
            html += '【' + jsonData.life.info.yundong[0] + '】 ' + jsonData.life.info.yundong[1] + '<br><br>';  
              
            html += '紫外线:<br>';  
            html += '【' + jsonData.life.info.ziwaixian[0] + '】 ' + jsonData.life.info.ziwaixian[1] + '<br><br>';  
              
            html += 'PM2.5: ' + jsonData.pm25.pm25[0];  
              
            $("#output").html(html);  
        }  
    });  
</script>  
  
</body>  
</html>

附:其它天气接口

天气网的接口(只支持iframe方式调用,修改后面的数字可以展示为其它样式)

http://i.tianqi.com/index.php?c=code&id=55

2345天气(只支持iframe方式调用,支持自定义样式)

http://tianqi.2345.com/plugin/

中国天气网(只支持iframe方式调用,支持自定义地区)

http://m.weather.com.cn/m/pn11/weather.htm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余十步

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值