Android程式之全國天氣預報查詢介面調用

來源:互聯網
上載者:User

標籤:天氣預報   android   

一、項目示範效果如下:

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-87357a9a8a909025?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />


650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-301ec100a0930e2a?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />


項目原始碼:

http://yunpan.cn/cZVWIieuFyK9I   訪問密碼 2eac

二、使用 彙總資料SDK:

(1)彙總資料官網地址:http://www.juhe.cn/

(2)註冊帳號—建立一個新應用(在個人中心頁面—資料中心—申請資料)–填入自己的應用–找到分類–天氣預報—全國天氣預報

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-68b6c0f74ed59dd2?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

(3)下載sdk (由於項目使用的是1點幾的版本,所以請下載:包含在我的項目中!)

(4)參考開發文檔:http://www.juhe.cn/juhesdk/adocs

這裡介紹了彙總資料SDK的初始化和許可權的使用!

三、項目介紹

(1)項目


650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-c8a8716ebe16d774?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

(2)WeatherApplication.java這裡作為sdk的初始化

package com.juhe.weather;import com.thinkland.juheapi.common.CommonFun;import android.app.Application;/** * 這裡是初始化彙總資料的SDK *  * 需要在application中添加 android:name="com.juhe.weather.WeatherApplication *  * @author xuliugen *  */public class WeatherApplication extends Application {    @Override    public void onCreate() {        super.onCreate();        // 使用彙總SDK需要初始化的過程        CommonFun.initialize(getApplicationContext());    }}

我們需要在資訊清單檔中加入:

android:name="com.juhe.weather.WeatherApplication"

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-c7628c09e8182dfa?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

(3)返回的json資料格式

{    "resultcode": "200",    "reason": "successed!",    "result": {        "sk": {            "temp": "19",            "wind_direction": "西北風",            "wind_strength": "1級",            "humidity": "37%",            "time": "16:00"        },        "today": {            "temperature": "5℃~19℃",            "weather": "多雲轉陰",            "weather_id": {                "fa": "01",                "fb": "02"            },            "wind": "南風微風",            "week": "星期五",            "city": "成都",            "date_y": "2015年03月13日",            "dressing_index": "較舒適",            "dressing_advice": "建議著薄外套、開衫牛仔衫褲等服裝。年老體弱者應適當添加衣物,宜著夾克衫、薄毛衣等。",            "uv_index": "最弱",            "comfort_index": "",            "wash_index": "較適宜",            "travel_index": "",            "exercise_index": "較不宜",            "drying_index": ""        },        "future": {            "day_20150313": {                "temperature": "5℃~19℃",                "weather": "多雲轉陰",                "weather_id": {                    "fa": "01",                    "fb": "02"                },                "wind": "南風微風",                "week": "星期五",                "date": "20150313"            },            "day_20150319": {                "temperature": "10℃~18℃",                "weather": "陰",                "weather_id": {                    "fa": "02",                    "fb": "02"                },                "wind": "南風微風",                "week": "星期四",                "date": "20150319"            }        }    },    "error_code": 0}未來三天的json資料格式:{    "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)根據上述的json格式,我們需要建立相應的json試題對象,其中為了更好的處理,分別建立相應的類

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-eefad7b7ebbafc9e?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-393528a81bb4c951?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

中就是含有內含項目關聯性的json資料,容易出錯!特此標記出來!

(5)WeatherService.java主要是處理後台服務的類,將資料的載入放在後台!

注意的是:

650) this.width=650;" src="http://upload-images.jianshu.io/upload_images/2699888-545d8100be25b7ab?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" class="imagebubble-image" style="height:auto;vertical-align:middle;border:0px;" alt="1240" />

這裡的白色部分的數值是在彙總資料上申請的時候的OpenID(在個人中心的中心首頁就可以找到OpenID!)


Android程式之全國天氣預報查詢介面調用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.