一、項(xiàng)目演示效果如下:
創(chuàng)新互聯(lián)是一家專業(yè)提供開(kāi)平企業(yè)網(wǎng)站建設(shè),專注與成都網(wǎng)站制作、成都做網(wǎng)站、HTML5建站、小程序制作等業(yè)務(wù)。10年已為開(kāi)平眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站制作公司優(yōu)惠進(jìn)行中。
項(xiàng)目源代碼下載地址:
http://yunpan.cn/cZVWIieuFyK9I 訪問(wèn)密碼 2eac
二、使用 聚合數(shù)據(jù)SDK:
(1)聚合數(shù)據(jù)官網(wǎng)地址:http://www.juhe.cn/
(2)注冊(cè)賬號(hào)—?jiǎng)?chuàng)建一個(gè)新應(yīng)用(在個(gè)人中心頁(yè)面—數(shù)據(jù)中心—申請(qǐng)數(shù)據(jù))–填入自己的應(yīng)用–找到分類–天氣預(yù)報(bào)—全國(guó)天氣預(yù)報(bào)
(3)下載sdk (由于項(xiàng)目使用的是1點(diǎn)幾的版本,所以請(qǐng)下載:包含在我的項(xiàng)目中!)
(4)參考開(kāi)發(fā)文檔:http://www.juhe.cn/juhesdk/adocs
這里介紹了聚合數(shù)據(jù)SDK的初始化和權(quán)限的使用!
三、項(xiàng)目介紹
(1)項(xiàng)目截圖
(2)WeatherApplication.java這里作為sdk的初始化
package com.juhe.weather;import com.thinkland.juheapi.common.CommonFun;import android.app.Application;/** * 這里是初始化聚合數(shù)據(jù)的SDK * * 需要在application中添加 android:name="com.juhe.weather.WeatherApplication * * @author xuliugen * */public class WeatherApplication extends Application { @Override public void onCreate() { super.onCreate(); // 使用聚合SDK需要初始化的過(guò)程 CommonFun.initialize(getApplicationContext()); } }
我們需要在清單文件中加入:
android:name="com.juhe.weather.WeatherApplication"
(3)返回的json數(shù)據(jù)格式
{ "resultcode": "200", "reason": "successed!", "result": { "sk": { "temp": "19", "wind_direction": "西北風(fēng)", "wind_strength": "1級(jí)", "humidity": "37%", "time": "16:00" }, "today": { "temperature": "5℃~19℃", "weather": "多云轉(zhuǎn)陰", "weather_id": { "fa": "01", "fb": "02" }, "wind": "南風(fēng)微風(fēng)", "week": "星期五", "city": "成都", "date_y": "2015年03月13日", "dressing_index": "較舒適", "dressing_advice": "建議著薄外套、開(kāi)衫牛仔衫褲等服裝。年老體弱者應(yīng)適當(dāng)添加衣物,宜著夾克衫、薄毛衣等。", "uv_index": "最弱", "comfort_index": "", "wash_index": "較適宜", "travel_index": "", "exercise_index": "較不宜", "drying_index": "" }, "future": { "day_20150313": { "temperature": "5℃~19℃", "weather": "多云轉(zhuǎn)陰", "weather_id": { "fa": "01", "fb": "02" }, "wind": "南風(fēng)微風(fēng)", "week": "星期五", "date": "20150313" }, "day_20150319": { "temperature": "10℃~18℃", "weather": "陰", "weather_id": { "fa": "02", "fb": "02" }, "wind": "南風(fēng)微風(fēng)", "week": "星期四", "date": "20150319" } } }, "error_code": 0 } 未來(lái)三天的json數(shù)據(jù)格式: { "resultcode": "200", "reason": "successed!", "result": [{ "weatherid": "01", "weather": "多云", "temp1": "16", "temp2": "13", "sh": "17", "eh": "20", "date": "20150313", "sfdate": "20150313170000", "efdate": "20150313200000" }, { "weatherid": "02", "weather": "陰", "temp1": "19", "temp2": "16", "sh": "11", "eh": "17", "date": "20150320", "sfdate": "20150320110000", "efdate": "20150320170000" }], "error_code": 0 }
(4)根據(jù)上述的json格式,我們需要?jiǎng)?chuàng)建相應(yīng)的json試題對(duì)象,其中為了更好的處理,分別建立相應(yīng)的類
上圖中就是含有包含關(guān)系的json數(shù)據(jù),容易出錯(cuò)!特此標(biāo)記出來(lái)!
(5)WeatherService.java主要是處理后臺(tái)服務(wù)的類,將數(shù)據(jù)的加載放在后臺(tái)!
注意的是:
這里的白色部分的數(shù)值是在聚合數(shù)據(jù)上申請(qǐng)的時(shí)候的OpenID(在個(gè)人中心的中心首頁(yè)就可以找到OpenID?。?/p>
新聞標(biāo)題:Android程序之全國(guó)天氣預(yù)報(bào)查詢接口調(diào)用
URL鏈接:http://weahome.cn/article/jppsos.html