国家气象局提供的天气预报接口(完整Json接口)

国家气象局提供的天气预报接口主要有三个,分别是:

http://www.weather.com.cn/data/sk/101010100.html

http://www.weather.com.cn/data/cityinfo/101010100.html

http://m.weather.com.cn/data/101010100.html

其中详细接口为:http://m.weather.com.cn/data/101010100.html

以下是http://m.weather.com.cn/data/101010100.html接口json格式提供,格式如下

{"weatherinfo":{

//基本信息

//fchh是系统更新时间

"city":"北京","city_en":"beijing","date_y":"2011年10月23 日","date":"辛卯年","week":"星期 日","fchh":"11","cityid":"101010100",

//6天内的温度

"temp1":"16℃~6℃","temp2":"16℃~3℃","temp3":"16℃~6℃","temp4":"14℃~6℃",

"temp5":"17℃~5℃","temp6":"18℃~8℃",

//6天内华氏度

"tempF1":"60.8℉~42.8℉","tempF2":"60.8℉~37.4℉","tempF3":"60.8℉~42.8℉",

"tempF4":"57.2℉~42.8℉","tempF5":"62.6℉~41℉","tempF6":"64.4℉~46.4℉",

//每日天气变化

"weather1":" 小雨转晴","weather2":"晴","weather3":"晴转阴","weather4":"多云转阴","weather5":"阴转 晴","weather6":"晴转多云",

//天气描述(图片序号)

"img1":"7","img2":"0","img3":"0","img4":"99","img5":"0","img6":"2","img7":"1",

"img8":"2","img9":"2","img10":"0","img11":"0","img12":"1","img_single":"7",

//天气描述(文字描述)

"img_title1":" 小雨","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴",

"img_title6":"阴","img_title7":"多云","img_title8":"阴","img_title9":"阴","img_title10":"晴",

"img_title11":"晴","img_title12":"多 云","img_title_single":"小雨",

//风向描述

"wind1":"北风4-5级","wind2":"北风3-4级转微 风","wind3":"微风","wind4":"微风","wind5":"微风",

"wind6":"微风","fx1":"北 风","fx2":"北风",

//风力描述

"fl1":"4-5级","fl2":"3-4级转小于3级","fl3":"小于3级","fl4":"小于3 级","fl5":"小于3级","fl6":"小于3级",

//今天穿衣指数

"index":"温凉","index_d":"较凉爽,建议着夹衣加薄羊毛衫等春秋服 装。体弱者宜着夹衣加羊毛衫。因昼夜温差较大,注意增减衣服。",

//48小时内穿衣指数

"index48":"温凉","index48_d":"较凉爽,建议着夹衣加薄羊毛 衫等春秋服装。体弱者宜着夹衣加羊毛衫。因昼夜温差较大,注意增减衣服。",

//紫外线

"index_uv":"最弱","index48_uv":"中 等",

//洗车

"index_xc":"不宜",

//旅游

"index_tr":"适宜",

//人体舒适度

"index_co":"较舒 适",

//未知

"st1":"14","st2":"3","st3":"14","st4":"5","st5":"15","st6":"5",

//晨练

"index_cl":" 较不宜",

//晾衣

"index_ls":"不宜",

//过敏

"index_ag":"极不易发"}}

当天基础天气接口

http://www.weather.com.cn/data/cityinfo/101010100.html

以下是http://www.weather.com.cn/data/cityinfo/101010100.html接口提供是Json格式提供,数据如下:

//ptime为系统最后更新时间

{"weatherinfo":{"city":"北 京","cityid":"101010100","temp1":"16℃","temp2":"6℃","weather":"小雨转 晴","img1":"d7.gif","img2":"n0.gif","ptime":"11:00"}}

当天基础天气接口

http://www.weather.com.cn/data/sk/101010100.html

以下是http://www.weather.com.cn/data/sk/101010100.html接口提供是Json格式提供,数据如下:

//temp为摄氏度

//isRadar 应该是雷达返回成功标识

//Radar是雷达编号

//time是该数据更新时间

{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"10","WD":"东北 风","WS":"4 级","SD":"56%","WSE":"4","time":"16:40","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}

字段名称
代码含义
city:城市名称 cityid:城市id day_y:当前时间
temp1:今天温度最低温和最高温 temp2:明天温度最低温和最高温
temp3:第三天温度最低温和最高温 temp4:第四天度最低温和最高温
temp5:第五天度最低温和最高温 temp6:第六天度最低温和最高温
weather1:今天天气描述 img1:今天白天温度图标
img3:明天白天温度图标 img5:第三天白天温度图标
img7:第四天白天温度图标 img9:第五天白天温度图标
img11:第六天白天温度图标

注意其中温度坐标字段(img1, img3, img5, img7, img9, img11)只是给出了图标的编号,需要拼接字符串来获取网络图片,比如得到img1,则图片地址为 http://m.weather.com.cn/img/b1.gif这个就是今天白天温度图标的图片网址,其中”b1.gif”就是图片的名字和样式,”b”表示这个图标是50*46像素,”1”就是”img”中的”1”,不同数字表示不同图标,获取图标后就可以通过Bitmap类型显示出来

public static List<Map<String, String>> getTodayWeather(String path) {  
  
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();  
    String json = null;  
    Map<String, String> map;  
  
    try {  
        String line = getConnection(path);  
        // 字符数组转换成字符串  
  
        if (line != null) {  
            json = new String(line);  
            // 这里是以对象的形式  
            JSONObject item1 = new JSONObject(json);  
            // 得到对象中的对象  
            JSONObject item = item1.getJSONObject("weatherinfo");  
  
            // 城市名字,阴天,3-4°,北风三级,湿度,日期  
            String city = item.getString("city");  
            String temp = item.getString("temp");  
            String wind = item.getString("WD") + item.getString("WS");  
            String wet = item.getString("SD");  
            String time = item.getString("time");  
  
            // 添加到MAP中  
  
            map = new HashMap<String, String>();  
  
            map.put("city", city);  
            map.put("temp", temp);  
            map.put("wind", wind);  
            map.put("wet", wet);  
            map.put("time", time);  
            list.add(map);  
        } else {  
            System.out.println("获取留数据失败!");  
        }  
  
    } catch (MalformedURLException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    } catch (ProtocolException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    } catch (IOException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    } catch (JSONException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  
    return list;  
}  



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值