获取天气预报json接口(官方接口)

中国天气weather.com
http://m.weather.com.cn/data/101110101.html(六天预报)

http://www.weather.com.cn/data/sk/101110101.html(实时天气信息)

其中101110101是城市的代码,获得城市代码进入

http://www.weather.com.cn
在搜索框上输入你要需要获得天气的城市,点击查询,即可在地址栏获得相应城市编号,然后替换
http://m.weather.com.cn/data/101110101.html

中国天气网城市代码:

101010100=北京
101010200=海淀
101010300=朝阳
101010400=顺义
101010500=怀柔
101010600=通州
101010700=昌平
101010800=延庆
101010900=丰台
101011000=石景山
101011100=大兴
101011200=房山
101011300=密云
101011400=门头沟
101011500=平谷
101011600=八达岭
101011700=佛爷顶
101011800=汤河口
101011900=密云上甸子
101012000=斋堂
101012100=霞云岭

101020100=上海
101020200=闵行
101020300=宝山
101020400=川沙
101020500=嘉定
101020600=南汇
101020700=金山
101020800=青浦
101020900=松江
101021000=奉贤
101021100=崇明
101021101=陈家镇
101021102=引水船
101021200=徐家汇
101021300=浦东

101030100=天津
101030200=武清
101030300=宝坻
101030400=东丽
101030500=西青
101030600=北辰
101030700=宁河
101030800=汉沽
101030900=静海
101031000=津南
101031100=塘沽
101031200=大港
101031300=平台
101031400=蓟县

101040100=重庆
101040200=永川
101040300=合川
101040400=南川
101040500=江津
101040600=万盛
101040700=渝北
101040800=北碚
101040900=巴南
101041000=长寿
101041100=黔江
101041200=万州天城
101041300=万州龙宝
101041400=涪陵
101041500=开县
101041600=城口
101041700=云阳
101041800=巫溪
101041900=奉节
101042000=巫山
101042100=潼南
101042200=垫江
101042300=梁平
101042400=忠县
101042500=石柱
101042600=大足
101042700=荣昌
101042800=铜梁
101042900=璧山
101043000=丰都
101043100=武隆
101043200=彭水
101043300=綦江
101043400=酉阳
101043500=金佛山
101043600=秀山
101043700=沙坪坝

101050101=哈尔滨
101050102=双城
101050103=呼兰
101050104=阿城
101050105=宾县
101050106=依兰
101050107=巴彦
101050108=通河
101050109=方正
101050110=延寿
101050111=尚志
101050112=五常
101050113=木兰
101050201=齐齐哈尔
101050202=讷河
101050203=龙江
101050204=甘南
101050205=富裕
101050206=依安
101050207=拜泉
101050208=克山
101050209=克东
101050210=泰来
101050301=牡丹江
101050302=海林
101050303=穆棱
101050304=林口
101050305=绥芬河
101050306=宁安
101050307=东宁
101050401=佳木斯
101050

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
天气查询APP,两种JSON解析方式 /** * 原始json数据解析 * */ // JSONObject jsonObject = new JSONObject(res); // String reason=jsonObject.getString("reason"); // if (reason.equals("参数不正确")){ // handler.sendEmptyMessage(1); // return; // } // JSONObject result=jsonObject.getJSONObject("result"); // JSONObject realtime=result.getJSONObject("realtime"); // JSONObject life=result.getJSONObject("life"); // JSONObject wind=realtime.getJSONObject("wind"); // String time=realtime.getString("time"); // JSONObject weather=realtime.getJSONObject("weather"); // String date=realtime.getString("date"); // dateStr=time+date; // weekStr=realtime.getString("week"); // calendarStr=realtime.getString("moon"); // windpowerStr=wind.getString("direct")+" "+wind.getString("power"); // weatherStr=weather.getString("info"); // temperatureStr=weather.getString("temperature"); // JSONObject info=life.getJSONObject("info"); // JSONArray kongtiao=info.getJSONArray("kongtiao"); // JSONArray yundong=info.getJSONArray("yundong"); // JSONArray ziwaixian=info.getJSONArray("ziwaixian"); // ACStr=kongtiao.getString(0)+" "+kongtiao.getString(1); // sportStr=yundong.getString(0)+" "+yundong.getString(1); // lightStr=ziwaixian.getString(0)+" "+ziwaixian.getString(1); /** * Gson数据解析 */ WheatherBean wheatherBean=new Gson().fromJson(res,WheatherBean.class); String reason=wheatherBean.getReason(); if (reason.equals("参数不正确")){ handler.sendEmptyMessage(1); return; } WheatherBean.ResultBean resultBean=wheatherBean.getResult(); WheatherBean.ResultBean.RealtimeBean realtimeBean=resultBean.getRealtime(); WheatherBean.ResultBean.RealtimeBean.WindBean windBean=realtimeBean.getWind(); String time=realtimeBean.getTime(); WheatherBean.ResultBean.RealtimeBean.WeatherBean weatherBean=realtimeBean.getWeather(); String date=realtimeBean.getDate(); dateStr=time+date; weekStr=realtimeBean.getWeek(); calendarStr=realtimeBean.getMoon(); windpowerStr=windBean.getDirect()+" "+windBean.getPower(); temperatureStr=weatherBean.getTemperature(); weatherStr=weatherBean.getInfo(); WheatherBean.ResultBean.LifeBean lifeBean=resultBean.getLife(); WheatherBean.ResultBean.LifeBean.InfoBean infoBean=lifeBean.getInfo(); List<String> kongtiao=infoBean.getKongtiao(); List<String> yundong=infoBean.getYundong(); List<String> ziwaixian=infoBean.getZiwaixian(); ACStr=kongtiao.get(0)+" "+kongtiao.get(1); sportStr=yundong.get(0)+" "+yundong.get(1); lightStr=ziwaixian.get(0)+" "+ziwaixian.get(1); }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值