使⽤json解析国家⽓象局(天⽓预报)接⼝数据平时我们在开发的过程中有时会要⽤到天⽓预报的信息,国家⽓象局为我们提供了天⽓预报的接⼝,只需要我们去解析就⾏了。很⽅便很好⽤那么下⾯,我们开始吧!
国家⽓象局提供了三种数据的形式
⽹址在:
最后⼀种是解析最全⾯的。
这⾥再附上中国天⽓⽹城市代码⼤全(百度⽂库⾥⾯的),把后⾯的城市代码换下就⾏了:
数据解析格式:
第⼀个⽹址提供的json数据为:
{"weatherinfo":{"city":"北京","cityid":"101010100","temp":"-2","WD":"西北风","WS":"3级","SD":"241%","WSE":"3","time":"10:61","isRadar":"1","Radar":"JC_RADAR_AZ9010_JB"}}
第⼆个⽹址提供的json数据为:
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"3℃","temp2":"-8℃","weather":"晴","img1":"d0.gif","img2":"n0.gif","ptime":"11:00"}}
第三个⽹址提供的json数据较为全⾯:
{
"weatherinfo":
{
"city":"北京",
"city_en":"beijing",
"date_y":"2013年1⽉17⽇",
"date":"",
"week":"星期四",
"fchh":"11",
"cityid":"101010100",
"temp1":"3℃~-8℃",
"temp2":"3℃~-5℃",
"temp3":"3℃~-3℃",
"temp4":"1℃~-5℃",
"temp5":"3℃~-6℃",
"temp6":"2℃~-5℃",
"tempF1":"37.4℉~17.6℉",
"tempF2":"37.4℉~23℉",
"tempF3":"37.4℉~26.6℉",
"tempF4":"33.8℉~23℉",
"tempF5":"37.4℉~21.2℉",
"tempF6":"35.6℉~23℉",
"weather1":"晴",
"weather2":"晴",
"weather3":"多云转阴",
"weather4":"阴转多云",
"weather5":"多云转晴",
"weather6":"晴转多云",
"img1":"0",
"img2":"99",
"img3":"0",
"img4":"99",
"img5":"1",
"img6":"2",
"img7":"2",
"img8":"1",
"img9":"1",
"img10":"0",
"img11":"0",
"img12":"1",
"img_single":"0",
"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":"微风",
"wind2":"微风",
"wind3":"微风",
"wind4":"微风",
"wind5":"微风",
"wind6":"微风",
"fx1":"微风",
"fx2":"微风",
"fl1":"⼩于3级",
"fl2":"⼩于3级",
"fl3":"⼩于3级",
"fl4":"⼩于3级",
"fl5":"⼩于3级",
"fl6":"⼩于3级",
"index":"冷",
"index_d":"天⽓冷,建议着棉⾐、⽪夹克加⽺⽑衫等冬季服装。年⽼体弱者宜着厚棉⾐或冬⼤⾐。",
"index48":"冷",
"index48_d":"天⽓冷,建议着棉⾐、⽪夹克加⽺⽑衫等冬季服装。年⽼体弱者宜着厚棉⾐或冬⼤⾐。",
"index_uv":"弱",
"index48_uv":"弱",
"index_xc":"适宜",
"index_tr":"较适宜",
"index_co":"较不舒适",
"st1":"2",
"st2":"-6",
"st3":"2",
"st4":"-3",
"st5":"3",
"st6":"-4",
"index_cl":"适宜",
"index_ls":"基本适宜",
"index_ag":"极不易发"
}
}
详细解析格式如下:
以json格式提供,格式如下 {"weatherinfo":{
//基本信息;
"city":"北京","city_en":"beijing",
"date_y":"2013年1⽉17⽇","date":"⾟卯年","week":"星期三","fchh":"18","cityid":"101010100",
//摄⽒温度
"temp1":"24℃~33℃","temp2":"24℃~32℃","temp3":"25℃~31℃","temp4":"23℃~30℃","temp5":"22℃~30℃","temp6":"21℃~32℃",
//华⽒温度;
"tempF1":"75.2℉~91.4℉","tempF2":"75.2℉~89.6℉","tempF3":"77℉~87.8℉","tempF4":"73.4℉~86℉","tempF5":"71.6℉~86℉","tempF6":"69.8℉~89.6℉", //天⽓描述;
"weather1":"多云","weather2":"晴转多云","weather3":"阴","weather4":"晴转阵⾬","weather5":"阵⾬","weather6":"多云",
//天⽓描述图⽚序号
"img1":"1","img2":"99","img3":"0","img4":"1","img5":"2","img6":"99","img7":"0","img8":"3","img9":"3","img10":"99","img11":"1","img12":"99",
"img_single":"1",
//图⽚名称;
"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":"微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",
/
/???
"fx1":"微风","fx2":"微风","fl1":"⼩于3级","fl2":"⼩于3级","fl3":"⼩于3级","fl4":"⼩于3级","fl5":"⼩于3级","fl6":"⼩于3级",
//今天穿⾐指数;
"index":"炎热","index_d":"天⽓炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。",
//48⼩时穿⾐指数
"index48":"炎热","index48_d":"天⽓炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。"
//紫外线及48⼩时紫外线
,"index_uv":"中等","index48_uv":"弱",
//洗车
"index_xc":"适宜",
//旅游
"index_tr":"较适宜",
//舒适指数
"index_co":"较不舒适",
//
"st1":"33","st2":"24","st3":"32","st4":"25","st5":"32","st6":"24",
//晨练
"index_cl":"适宜",
//晾晒
"index_ls":"适宜",
/
/过敏
"index_ag":"极易发"}}
字段⾔简意赅,城市名,英⽂名,⽇期,农历⽇期,星期,预报时间,城市代码,6个预报温度(华⽒温度,摄⽒温度),6个预报天⽓和风⼒,剩下的就是⼀些⽓象指数。
  之前有朋友提到过,希望把各个城市的城市代码也整理⼀下,这样的话,可以跟⽅便的使⽤,经过查,在百度⽂库⾥⾯到⼀篇详细的城市代码。⼤家可以去查看,地址如下,祝⼤家使⽤愉快:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。