Android程序之全国天气预报查询API调用

一、项目演示效果如下:

20160922113150

二、使用 聚合数据SDK:
(1)聚合数据官网地址:http://www.juhe.cn/

(2)注册账号—创建一个新应用(在个人中心页面—数据中心—申请数据)–填入自己的应用–找到分类–天气预报—全国天气预报

(3)下载sdk (由于项目使用的是1点几的版本,所以请下载:包含在我的项目中!)

(4)参考开发文档:http://www.juhe.cn/juhesdk/adocs

这里介绍了聚合数据SDK的初始化和权限的使用!

三、项目介绍
(1)项目截图
20160922113250

(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”

(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
}

注意的是:
这里的白色部分的数值是在聚合数据上申请的时候的OpenID(在个人中心的中心首页就可以找到OpenID!)


原文链接:,转发请注明来源!

发表评论

要发表评论,您必须先登录