⑴ iOS開發,想知道國家氣象局api返回過來的天氣數據將天氣總共描述為幾種類型,
之前做過相關的App,網上搜出來的,直接粘貼了。有用請採納哦~
國家氣象局提供的天氣預報介面
介面地址:
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
對於第三個介面,返回信息比較全面,也是以json格式提供,格式如下
{"weatherinfo": {//基本信息;"city":"北京","city_en":"beijing","date_y":"2012年2月16日", "date":"", "week":"星期四", "fchh":"11", "cityid":"101010100",//攝氏溫度"temp1":"2℃~-7℃","temp2":"1℃~-7℃","temp3":"4℃~-7℃","temp4":"7℃~-5℃","temp5":"5℃~-3℃","temp6":"5℃~-2℃",//華氏溫度;"tempF1":"35.6℉~19.4℉","tempF2":"33.8℉~19.4℉","tempF3":"39.2℉~19.4℉","tempF4":"44.6℉~23℉","tempF5":"41℉~26.6℉","tempF6":"41℉~28.4℉",//天氣描述;"weather1":"晴","weather2":"晴","weather3":"晴","weather4":"晴轉多雲","weather5":"多雲","weather6":"多雲轉陰",//天氣描述圖片序號"img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"2","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":"北風3-4級轉微風","wind2":"微風","wind3":"微風","wind4":"微風","wind5":"微風","wind6":"微風",//風速級別描述"fx1":"北風","fx2":"微風","fl1":"3-4級轉小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3級","fl6":"小於3級",//今天穿衣指數;"index":"冷","index_d":"天氣冷,建議著棉衣、皮夾克加羊毛衫等冬季服裝。年老體弱者宜著厚棉衣或冬大衣。",//48小時穿衣指數"index48":"冷","index48_d":"天氣冷,建議著棉衣、皮夾克加羊毛衫等冬季服裝。年老體弱者宜著厚棉衣或冬大衣。",//紫外線及48小時紫外線"index_uv":"弱","index48_uv":"弱",//洗車"index_xc":"適宜",//旅遊"index_tr":"一般",//舒適指數"index_co":"較不舒適","st1":"1","st2":"-8","st3":"2","st4":"-4","st5":"5","st6":"-5",//晨練"index_cl":"較不宜",//晾曬"index_ls":"基本適宜",//過敏"index_ag":"極不易發"}}
全國各城市代碼如下:
北京:101010100朝陽:101010300順義:101010400懷柔:101010500通州:101010600昌平:101010700延慶:101010800豐台:101010900石景山:101011000大興:101011100房山:101011200密雲:101011300門頭溝:101011400平谷:101011500八達嶺:101011600佛爺頂:101011700湯河口:101011800密雲上甸子:101011900齋堂:101012000霞雲嶺:101012100北京城區:101012200海淀:101010200天津:101030100寶坻:101030300東麗:101030400西青:101030500北辰:101030600薊縣:101031400漢沽:101030800靜海:101030900津南:101031000塘沽:101031100大港:101031200武清:101030200寧河:101030700上海:101020100寶山:101020300嘉定:101020500南匯:101020600浦東:101021300青浦:101020800松江:101020900奉賢:101021000崇明:101021100徐家匯:101021200閔行:101020200金山:101020700石家莊:101090101張家口:101090301承德:101090402唐山:101090501秦皇島:101091101滄州:101090701衡水:101090801邢台:101090901邯鄲:101091001保定:101090201廊坊:101090601鄭州:101180101新鄉:101180301許昌:101180401平頂山:101180501信陽:101180601南陽:101180701開封:101180801洛陽:101180901商丘:101181001焦作:101181101鶴壁:101181201濮陽:101181301周口:101181401漯河:101181501駐馬店:101181601三門峽:101181701濟源:101181801安陽:101180201合肥:101220101蕪湖:101220301淮南:101220401馬鞍山:101220501安慶:101220601宿州:101220701阜陽:101220801亳州:101220901黃山:101221001滁州:101221101淮北:101221201銅陵:101221301宣城:101221401六安:101221501巢湖:101221601池州:101221701蚌埠:101220201杭州:101210101舟山:101211101湖州:101210201嘉興:101210301金華:101210901紹興:101210501台州:101210601溫州:101210701麗水:101210801衢州:101211001寧波:101210401重慶:101040100合川: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秀山:101043600沙坪壩:101043700永川:101040200福州:101230101泉州:101230501漳州:101230601龍岩:101230701晉江:101230509南平:101230901廈門:101230201寧德:101230301莆田:101230401三明:101230801蘭州:101160101平涼:101160301慶陽:101160401武威:101160501金昌:101160601嘉峪關:101161401酒泉:101160801天水:101160901武都:101161001臨夏:101161101合作:101161201白銀:101161301定西:101160201張掖:101160701廣州:101280101惠州:101280301梅州:101280401汕頭:101280501深圳:101280601珠海:101280701佛山:101280800肇慶:101280901湛江:101281001江門:101281101河源:101281201清遠:101281301雲浮:101281401潮州:101281501東莞:101281601中山:101281701陽江:101281801揭陽:101281901茂名:101282001汕尾:101282101韶關:101280201南寧:101300101柳州:101300301來賓:101300401桂林:101300501梧州:101300601防城港:101301401貴港:101300801玉林:101300901百色:101301001欽州:101301101河池:101301201北海:101301301崇左:101300201賀州:101300701貴陽:101260101安順:101260301都勻:101260401興義:101260906銅仁:101260601畢節:101260701六盤水:101260801遵義:101260201凱里:101260501昆明:101290101紅河:101290301文山:101290601玉溪:101290701楚雄:101290801普洱:101290901昭通:101291001臨滄:101291101怒江:101291201香格里拉:101291301麗江:101291401德宏:101291501景洪:101291601大理:101290201曲靖:101290401保山:101290501呼和浩特:101080101烏海:101080301集寧:101080401通遼:101080501阿拉善左旗:101081201鄂爾多斯:101080701臨河:101080801錫林浩特:101080901呼倫貝爾:101081000烏蘭浩特:101081101包頭:101080201赤峰:101080601南昌:101240101上饒:101240301撫州:101240401宜春:101240501鷹潭:101241101贛州:101240701景德鎮:101240801萍鄉:101240901新余:101241001九江:101240201吉安:101240601武漢:101200101黃岡:101200501荊州:101200801宜昌:101200901恩施:101201001十堰:101201101神農架:101201201隨州:101201301荊門:101201401天門:101201501仙桃:101201601潛江:101201701襄樊:101200201鄂州:101200301孝感:101200401黃石:101200601咸寧:101200701成都:101270101自貢:101270301綿陽:101270401南充:101270501達州:101270601遂寧:101270701廣安:101270801巴中:101270901瀘州:101271001宜賓:101271101內江:101271201資陽:101271301樂山:101271401眉山:101271501涼山:101271601雅安:101271701甘孜:101271801阿壩:101271901德陽:101272001廣元:101272101攀枝花:101270201銀川:101170101中衛:101170501固原:101170401石嘴山:101170201吳忠:101170301西寧:101150101黃南:101150301海北:101150801果洛:101150501玉樹:101150601海西:101150701海東:101150201海南:101150401濟南:101120101濰坊:101120601臨沂:101120901菏澤:101121001濱州:101121101東營:101121201威海:101121301棗庄:101121401日照:101121501萊蕪:101121601聊城:101121701青島:101120201淄博:101120301德州:101120401煙台:101120501濟寧:101120701泰安:101120801西安:101110101延安:101110300榆林:101110401銅川:101111001商洛:101110601安康:101110701漢中:101110801寶雞:101110901咸陽:101110200渭南:101110501太原:101100101臨汾:101100701運城:101100801朔州:101100901忻州:101101001長治:101100501大同:101100201陽泉:101100301晉中:101100401晉城:101100601呂梁:101101100烏魯木齊:101130101石河子:101130301昌吉:101130401吐魯番:101130501庫爾勒:101130601阿拉爾:101130701阿克蘇:101130801喀什:101130901伊寧:101131001塔城:101131101哈密:101131201和田:101131301阿勒泰:101131401阿圖什:101131501博樂:101131601克拉瑪依:101130201拉薩:101140101山南:101140301阿里:101140701昌都:101140501那曲:101140601日喀則:101140201林芝:101140401台北縣:101340101高雄:101340201台中:101340401海口:101310101三亞:101310201東方:101310202臨高:101310203澄邁:101310204儋州:101310205昌江:101310206白沙:101310207瓊中:101310208定安:101310209屯昌:101310210瓊海:101310211文昌:101310212保亭:101310214萬寧:101310215陵水:101310216西沙:101310217南沙島:101310220樂東:101310221五指山:101310222瓊山:101310102長沙:101250101株洲:101250301衡陽:101250401郴州:101250501常德:101250601益陽:101250700婁底:101250801邵陽:101250901岳陽:101251001張家界:101251101懷化:101251201黔陽:101251301永州:101251401吉首:101251501湘潭:101250201南京:101190101鎮江:101190301蘇州:101190401南通:101190501揚州:101190601宿遷:101191301徐州:101190801淮安:101190901連雲港:101191001常州:101191101泰州:101191201無錫:101190201鹽城:101190701哈爾濱:101050101牡丹江:101050301佳木斯:101050401綏化:101050501黑河:101050601雙鴨山:101051301伊春:101050801大慶:101050901七台河:101051002雞西:101051101鶴崗:101051201齊齊哈爾:101050201大興安嶺:101050701長春:101060101延吉:101060301四平:101060401白山:101060901白城:101060601遼源:101060701松原:101060801吉林:101060201通化:101060501沈陽:101070101鞍山:101070301撫順:101070401本溪:101070501丹東:101070601葫蘆島:101071401營口:101070801阜新:101070901遼陽:101071001鐵嶺:101071101朝陽:101071201盤錦:101071301大連:101070201錦州:101070701
1. XML介面 http://flash.weather.com.cn/wmaps/xml/china.xml 這個是全國天氣的根節點,列出所有的省,其中的pyName欄位是各個省XML的文件名,比如北京的是beijing,那就意味著北京的XML地址為 http://flash.weather.com.cn/wmaps/xml/beijing.xml 一個省的天氣,其中列出該省各個市的數據,北京就列出各個區。 tmp1是最低溫低,tmp2是最高溫度,url非常重要,我們一會兒再說。state1和state2是神馬轉神馬,每個數代表一個天氣現象。天氣現象非常多,我本想全部分析出來,後來直接放棄了這個想法。因為我看到了一個城市的天氣現象的編碼是26...我現在知道的有0.晴 1.多雲 2.陰 6.雨夾雪 7.小雨 8.中雨 13.陣雪 14.小雪 其中後來發現知道這個沒用,這個數字的主要作用是檢索圖片的!!!
2. 圖片介面 http://m.weather.com.cn/img/c0.gif http://m.weather.com.cn/img/b0.gif http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif 這個圖就是天氣現象0(晴)的圖片,其他天氣現象的圖片依此類推。c打頭的圖片是20*20像素的,b打頭的是50*46像素的,d打頭的是反白的圖標,29*20像素,n打頭的是夜間反白圖標,29*20像素,注意這里的文件名是兩位數字! 也許還有更多的圖標,等待大家發掘啦~
3. JSON介面 真沒想到~居然有JSON介面~JSON在iPhone上分析起來要比XML簡單很多 http://m.weather.com.cn/data/101010200.html 這個是北京的JSON數據,那個HTML的名字是根據上文XML中的url得到的。這個JSON中包含了實時數據、7天天氣預報、氣象指數等豐富的數據
獲取省級代碼:http://www.weather.com.cn/data/list3/city.xml?level=1獲取城市代碼(比如安徽是22):http://www.weather.com.cn/data/list3/city22.xml?level=2獲取區域代碼(比如安慶是2206):http://www.weather.com.cn/data/list3/city2206.xml?level=3獲取到安徽省安慶市望江縣的代碼是220607然後去加上中國代碼請求URL:http://m.weather.com.cn/data/101220607.html就可以獲取當地天氣。
另外再給幾個有用的探索得到的URL:天氣 FLASH實況:http://flash.weather.com.cn/sk2/101220607.xml實況FLASH:http://flash.weather.com.cn/sk2/shikuang.swf?id=101220607
三級選擇菜單(註明,這里有四個INPUT,其中有一個被隱藏了,可用FIREFOX改下源代碼查看):http://www.weather.com.cn/static/custom/search3.htm
實時天氣(很有用哦):http://www.weather.com.cn/data/sk/101220607.html
1. XML介面
http://flash.weather.com.cn/wmaps/xml/china.xml
這個是全國天氣的根節點,列出所有的省,其中的pyName欄位是各個省XML的文件名,比如北京的是beijing,那就意味著北京的XML地址為
http://flash.weather.com.cn/wmaps/xml/beijing.xml
一個省的天氣,其中列出該省各個市的數據,北京就列出各個區。
tmp1是最低溫低,tmp2是最高溫度,url非常重要,我們一會兒再說。state1和state2是神馬轉神馬,每個數代表一個天氣現 象。天氣現象非常多,我本想全部分析出來,後來直接放棄了這個想法。因為我看到了一個城市的天氣現象的編碼是26...我現在知道的有0.晴 1.多雲 2.陰 6.雨夾雪 7.小雨 8.中雨 13.陣雪 14.小雪
其中後來發現知道這個沒用,這個數字的主要作用是檢索圖片的!!!
2. 圖片介面
http://m.weather.com.cn/img/c0.gif
http://m.weather.com.cn/img/b0.gif
http://www.weather.com.cn/m/i/weatherpic/29x20/d0.gif
http://www.weather.com.cn/m2/i/icon_weather/29x20/n00.gif
這個圖就是天氣現象0(晴)的圖片,其他天氣現象的圖片依此類推。c打頭的圖片是20*20像素的,b打頭的是50*46像素的,d打頭的是反白的圖標,29*20像素,n打頭的是夜間反白圖標,29*20像素,注意這里的文件名是兩位數字!
3. JSON介面
http://m.weather.com.cn/data/101010100.htmlhttp://www.weather.com.cn/data/sk/101010100.htmlhttp://www.weather.com.cn/data/cityinfo/101010100.html