1. 程式人生 > >Android——呼叫百度天氣API實現天氣預報

Android——呼叫百度天氣API實現天氣預報

專案中有需求要加入天氣當地天氣預報功能,我的做法很簡單,使用的百度天氣API提供天氣資料,使用Xutils進行請求,用GSON進行的資料解析,反正已經有人造好了輪子,直接拿來用就是。

百度天氣使用的是車聯網API,值得提出的一點是,由於API更新後,你所建立的應用型別,夠選為伺服器,新申請的Mobile與Browser型別的ak不再支援雲端儲存介面的訪問,如要使用雲端儲存,請申請Server型別ak。

下面是車聯網API

介面說明

根據經緯度/城市名查詢天氣的結果

介面示例

介面引數說明

引數型別 引數名稱 是否必須 具體描述
String ak true 開發者金鑰
String sn false 若使用者所用ak的校驗方式為sn校驗時該引數必須。 (sn生成演算法)
String location true "分隔,location=116.305145,39.982368| 122.305145,36.982368|….
String output false 輸出的資料格式,預設為xml格式,當output設定為’json’時,輸出的為json格式的資料;
String coord_type false 請求引數座標型別,預設為gcj02經緯度座標。允許的值為bd09ll、bd09mc、gcj02、wgs84。bd09ll表示百度經緯度座標,bd09mc表示百度墨卡託座標,gcj02表示經過國測局加密的座標。wgs84表示gps獲取的座標。
String callback false 將json格式的返回值通過callback函式返回以實現jsonp功能。舉例:callback=showLocation(JavaScript函式名)。

返回結果

引數名稱 含義 說明
currentCity 當前城市 返回城市名
status 返回結果狀態資訊 請求狀態,如果成功返回0,如果失敗返回其他數字,詳細見狀態碼附錄。
date 當前時間 年-月-日
results 天氣預報資訊 白天可返回近期3天的天氣情況(今天、明天、後天)、晚上可返回近期4天的天氣情況(今天、明天、後天、大後天)
results.currentCity 當前城市
results.pm25 pm2.5 0~50,一級,優,綠色;

51~100,二級,良,黃色; 101~150,三級,輕度汙染,橙色; 151~200,四級,中度汙染 ,紅色; 201~300,五級,重度汙染 ,紫色; >300,六級,嚴重汙染, 褐紅色。 圖示分類示意圖: pm25green.png 優, pm25yellow.png 良 , pm25orange.png 輕度汙染,pm25red.png 中度汙染,pm25purple.png 重度汙染, pm25balck.png 嚴重汙染。

results.index.title 指數title 分為:穿衣、洗車、感冒、運動、紫外線這幾個型別。
results.index.zs 指數取值 不同指數描述不一
results.index.tipt 指數含義 指數含義
results.index.des 指數詳情 指數詳情
results.weather_data weather_data.date 天氣預報時間
weather_data.dayPictureUrl 白天的天氣預報圖片url
weather_data.nightPictureUrl 晚上的天氣預報圖片url
weather_data.weather 天氣狀況 常見天氣情況(“|”分隔符):晴|多雲|陰|陣雨|雷陣雨|雷陣雨伴有冰雹|雨夾雪|小雨|中雨|大雨|暴雨|大暴雨|特大暴雨|陣雪|小雪|中雪|大雪|暴雪|霧|凍雨|沙塵暴|小雨轉中雨|中雨轉大雨|大雨轉暴雨|暴雨轉大暴雨|大暴雨轉特大暴雨|小雪轉中雪|中雪轉大雪|大雪轉暴雪|浮塵|揚沙|強沙塵暴|霾
weather_data.wind 風力 風力值
weather_data.temperature 溫度 溫度範圍,如:29~22℃

返回xml格式的資料

<CityWeatherResponse>
<status>success</status>
<date>2013-07-18</date>
<results>
<currentCity>北京市</currentCity>
<weather_data>
<date>週三(今天, 實時:24℃)</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>微風</wind>
<temperature>23℃~ 15℃</temperature>
<date>週四</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/leizhenyu.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/zhongyu.png
</nightPictureUrl>
<weather>雷陣雨轉中雨</weather>
<wind>微風</wind>
<temperature>29~22℃</temperature>
<date>週五</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/yin.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>陰轉多雲</weather>
<wind>微風</wind>
<temperature>31~23℃</temperature>
<date>週六</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>微風</wind>
<temperature>31~24℃</temperature>
</weather_data>
<currentCity>合肥市</currentCity>
<weather_data>
<date>週三</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>東風3-4級</wind>
<temperature>27℃</temperature>
<date>週四</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>東北風3-4級</wind>
<temperature>35~27℃</temperature>
<date>週五</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>南風</wind>
<temperature>35~27℃</temperature>
<date>週六</date>
<dayPictureUrl>
http://api.map.baidu.com/images/weather/day/duoyun.png
</dayPictureUrl>
<nightPictureUrl>
http://api.map.baidu.com/images/weather/night/duoyun.png
</nightPictureUrl>
<weather>多雲</weather>
<wind>東風</wind>
<temperature>34~27℃</temperature>
</weather_data>
</results>
</CityWeatherResponse>
<weather>陣雨</weather>
<wind>東北風3-4級</wind>
<temperature>18℃</temperature>
<index>
<title>穿衣</title>
<zs>舒適</zs>
<tipt>穿衣指數</tipt>
<des>建議著長袖T恤、襯衫加單褲等服裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。</des>
<title>洗車</title>
<zs>不宜</zs>
<tipt>洗車指數</tipt>
<des>不宜洗車,未來24小時內有雨,如果在此期間洗車,雨水和路上的泥水可能會再次弄髒您的愛車。</des>
<title>感冒</title>
<zs>較易發</zs>
<tipt>感冒指數</tipt>
<des>相對今天出現了較大幅度降溫,較易發生感冒,體質較弱的朋友請注意適當防護。</des>
<title>運動</title>
<zs>較不宜</zs>
<tipt>運動指數</tipt>
<des>有降水,推薦您在室內進行健身休閒運動;若堅持戶外運動,須注意攜帶雨具並注意避雨防滑。</des>
<title>紫外線強度</title>
<zs>弱</zs>
<tipt>紫外線強度指數</tipt>
<des>紫外線強度較弱,建議出門前塗擦SPF在12-15之間、PA+的防晒護膚品。</des>
</index>
<pm25>166</pm25>
</results>
</CityWeatherResponse>

返回json格式的資料

{
error: 0,
status: "success",
date: "2013-07-17",
results: 
[
{
currentCity: "北京市",
pm25: "166",
index: [
{
title: "穿衣",
zs: "舒適",
tipt: "穿衣指數",
des: "建議著長袖T恤、襯衫加單褲等服裝。年老體弱者宜著針織長袖襯衫、馬甲和長褲。"
},
{
title: "洗車",
zs: "不宜",
tipt: "洗車指數",
des: "不宜洗車,未來24小時內有雨,如果在此期間洗車,雨水和路上的泥水可能會再次弄髒您的愛車。"
},
{
title: "感冒",
zs: "較易發",
tipt: "感冒指數",
des: "相對今天出現了較大幅度降溫,較易發生感冒,體質較弱的朋友請注意適當防護。"
},
{
title: "運動",
zs: "較不宜",
tipt: "運動指數",
des: "有降水,推薦您在室內進行健身休閒運動;若堅持戶外運動,須注意攜帶雨具並注意避雨防滑。"
},
{
title: "紫外線強度",
zs: "弱",
tipt: "紫外線強度指數",
des: "紫外線強度較弱,建議出門前塗擦SPF在12-15之間、PA+的防晒護膚品。"
}
],
weather_data: 
[
{
date: "週三(今天, 實時:24℃)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "微風",
temperature: "23℃~ 15℃"
},
{
date: "明天(週四)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
weather: "雷陣雨轉中雨",
wind: "微風",
temperature: "29~22℃"
},
{
date: "後天(週五)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "陰轉多雲",
wind: "微風",
temperature: "31~23℃"
},
{
date: "大後天(週六)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "微風",
temperature: "31~24℃"
}
]
},
{
currentCity: "合肥市",
weather_data: 
[
{
date: "今天(週三)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "東風3-4級",
temperature: "27℃"
},
{
date: "明天(週四)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "東北風3-4級",
temperature: "35~27℃"
},
{
date: "後天(週五)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "南風",
temperature: "35~27℃"
},
{
date: "大後天(週六)",
dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
weather: "多雲",
wind: "東風",
temperature: "34~27℃"
}
]
}
]
}
直接上程式碼:

效果圖:


佈局檔案程式碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ba_weather"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/cityTitle"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="10dp"
        android:text="city"
        android:textColor="@color/white"
        android:textSize="15sp" />

    <ImageView
        android:id="@+id/iv_status_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:paddingTop="100dp" />

    <TextView
        android:paddingTop="5dp"
        android:id="@+id/tv_currentday_status"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:gravity="center_horizontal"
        android:text="status"
        android:textColor="@color/white"
        android:textSize="15sp" />

    <TextView
        android:id="@+id/tv_currentday_temp"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:gravity="center_horizontal"
        android:text="currtem"
        android:textColor="@color/white"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/tv_currentday_wind"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:gravity="center_horizontal"
        android:text="wind"
        android:textColor="@color/white"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/tv_currentday_data"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:gravity="center_horizontal"
        android:text="week"
        android:textColor="@color/white"
        android:textSize="10sp" />

    <LinearLayout
        android:layout_marginTop="60dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >

        <TextView
            android:paddingLeft="5dp"
            android:id="@+id/tv_flue"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/white"
            android:textSize="10sp" />

        <TextView
              android:paddingLeft="5dp"
              android:paddingRight="5dp"
            android:id="@+id/tv_fluedetails"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/white"
            android:textSize="10sp"
            android:textStyle="italic" />

        <TextView
              android:paddingLeft="5dp"
            android:id="@+id/tv_support"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/white"
            android:textSize="10sp" />

        <TextView
              android:paddingLeft="5dp"
              android:paddingRight="5dp"
            android:id="@+id/tv_supportdetails"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/white"
            android:textSize="10sp"
            android:textStyle="italic" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="80dp"
        android:orientation="horizontal" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" >

            <ImageView
                android:id="@+id/iv_firststatus_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:id="@+id/first_status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_firststatus_image"
                android:gravity="center_horizontal"
                android:paddingLeft="4dp"
                android:paddingTop="5dp"
                android:text="status"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp" >

            <TextView
                android:id="@+id/first_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="3dp"
                android:text="週三"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/first_tem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/first_data"
                android:gravity="center_horizontal"
                android:paddingTop="8dp"
                android:text="-2-10"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:src="@drawable/line_weather" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" >

            <ImageView
                android:id="@+id/iv_secondstatus_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:id="@+id/second_status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_secondstatus_image"
                android:gravity="center_horizontal"
                android:paddingLeft="4dp"
                android:paddingTop="5dp"
                android:text="晴"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp" >

            <TextView
                android:id="@+id/second_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="3dp"
                android:text="週三"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/second_tem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/second_data"
                android:gravity="center_horizontal"
                android:paddingTop="8dp"
                android:text="-2-10"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:gravity="center_horizontal"
            android:src="@drawable/line_weather" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp" >

            <ImageView
                android:id="@+id/iv_thirdnstatus_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />

            <TextView
                android:id="@+id/third_status"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/iv_thirdnstatus_image"
                android:gravity="center_horizontal"
                android:paddingLeft="4dp"
                android:paddingTop="5dp"
                android:text="晴"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp" >

            <TextView
                android:id="@+id/third_data"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_horizontal"
                android:paddingLeft="3dp"
                android:text="週三"
                android:textColor="@color/white"
                android:textSize="10sp" />

            <TextView
                android:id="@+id/third_tem"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/third_data"
                android:gravity="center_horizontal"
                android:paddingTop="8dp"
                android:text="-2-10"
                android:textColor="@color/white"
                android:textSize="10sp" />
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>
實現程式碼:
import java.util.ArrayList;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.cykj.oa.app.R;
import com.cykj.oa.app.base.BaseActivity;
import com.cykj.oa.app.bean.EmailBean;
import com.cykj.oa.app.bean.EmailBean.Messages;
import com.cykj.oa.app.bean.WeatherBean;
import com.cykj.oa.app.bean.WeatherBean.results;
import com.cykj.oa.app.utils.GsonTools;
import com.cykj.oa.app.utils.OAApi;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.lidroid.xutils.util.LogUtils;

public class WeatherShowActiviy extends BaseActivity {
	private TextView tv_cityTitle;
	private ImageView iv_status_iamge;
	private TextView tv_currentday_status;
	private TextView tv_currentday_temp;
	private TextView tv_currentday_wind;
	private TextView tv_currentday_data;

	
	
	private TextView tv_flue;
	private TextView tv_fluedetails;
	private TextView tv_support;
	
	private TextView tv_supportdetails;
	
	
	
	private ImageView iv_firststatus_iamge;
	private TextView first_data;
	private TextView first_status;
	private TextView first_tem;
	
	private ImageView iv_secondstatus_iamge;
	private TextView second_data;
	private TextView second_status;
	private TextView second_tem;
	
	private ImageView iv_thirdstatus_iamge;
	private TextView third_data;
	private TextView third_status;
	private TextView third_tem;

	private WeatherBean weatherBean;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.weather);
		findViewById();
		initView();
	}

	@Override
	protected void findViewById() {
		tv_cityTitle = (TextView) findViewById(R.id.cityTitle);
		iv_status_iamge = (ImageView) findViewById(R.id.iv_status_image);
		tv_currentday_status = (TextView) findViewById(R.id.tv_currentday_status);
		tv_currentday_temp = (TextView) findViewById(R.id.tv_currentday_temp);
		tv_currentday_wind = (TextView) findViewById(R.id.tv_currentday_wind);
		tv_currentday_data = (TextView) findViewById(R.id.tv_currentday_data);

		tv_flue = (TextView) findViewById(R.id.tv_flue);
		tv_fluedetails = (TextView) findViewById(R.id.tv_fluedetails);
		tv_support = (TextView) findViewById(R.id.tv_support);
		tv_supportdetails = (TextView) findViewById(R.id.tv_supportdetails);
		
		
		first_data = (TextView) findViewById(R.id.first_data);
		first_status = (TextView) findViewById(R.id.first_status);
		first_tem = (TextView) findViewById(R.id.first_tem);

		second_data = (TextView) findViewById(R.id.second_data);
		second_status = (TextView) findViewById(R.id.second_status);
		second_tem = (TextView) findViewById(R.id.second_tem);

		third_data = (TextView) findViewById(R.id.third_data);
		third_status = (TextView) findViewById(R.id.third_status);
		third_tem = (TextView) findViewById(R.id.third_tem);

		
		iv_firststatus_iamge = (ImageView) findViewById(R.id.iv_firststatus_image);
		iv_secondstatus_iamge = (ImageView) findViewById(R.id.iv_secondstatus_image);
		iv_thirdstatus_iamge = (ImageView) findViewById(R.id.iv_thirdnstatus_image);
		
	}

	@Override
	protected void initView() {
		HttpUtils http = new HttpUtils();
		http.send(HttpRequest.HttpMethod.GET, OAApi.WEATHER_URL,
				new RequestCallBack<String>() {

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						LogUtils.d("獲取結果 :" + responseInfo.result);
						ProcessData(responseInfo.result);
					}

					@Override
					public void onFailure(HttpException error, String msg) {
						LogUtils.d("獲取失敗 :" + error);
					}
				});

	}

	public void ProcessData(String result) {
		weatherBean = GsonTools.changeGsonToBean(result, WeatherBean.class);
		if (weatherBean.status = true) {
			ArrayList<results> s = weatherBean.results;
			System.out.println("weather:" + s);
		}
		
		BitmapUtils bitmapUtils = new BitmapUtils(this);
		
		// 載入網路圖片
		bitmapUtils.display(iv_status_iamge, weatherBean.results.get(0).weather_data.get(0).dayPictureUrl);
		bitmapUtils.display(iv_firststatus_iamge, weatherBean.results.get(0).weather_data.get(1).dayPictureUrl);
		bitmapUtils.display(iv_secondstatus_iamge, weatherBean.results.get(0).weather_data.get(2).dayPictureUrl);
		bitmapUtils.display(iv_thirdstatus_iamge, weatherBean.results.get(0).weather_data.get(3).dayPictureUrl);
		
		System.out.println("weather_url:"+weatherBean.results.get(0).weather_data.get(0).dayPictureUrl);
		tv_cityTitle.setText(weatherBean.results.get(0).currentCity);
		System.out.println("city"+weatherBean.results.get(0).currentCity);
		
		tv_flue.setText(weatherBean.results.get(0).index.get(3).title+":"+weatherBean.results.get(0).index.get(3).zs);
		tv_fluedetails.setText(weatherBean.results.get(0).index.get(3).des);
		tv_support.setText(weatherBean.results.get(0).index.get(4).title+":"+weatherBean.results.get(0).index.get(4).zs);
		tv_supportdetails.setText(weatherBean.results.get(0).index.get(4).des);

		tv_currentday_status.setText(weatherBean.results.get(0).weather_data.get(0).weather);
		System.out.println("weather"+weatherBean.results.get(0).weather_data.get(0).weather);
		
		tv_currentday_wind.setText(weatherBean.results.get(0).weather_data.get(0).wind);
		tv_currentday_data.setText(weatherBean.results.get(0).weather_data.get(0).date);
		System.out.println("data"+weatherBean.results.get(0).weather_data.get(0).date);
		tv_currentday_temp.setText(weatherBean.results.get(0).weather_data.get(0).temperature);
		System.out.println("temperature"+weatherBean.results.get(0).weather_data.get(0).temperature);
		
		first_data.setText(weatherBean.results.get(0).weather_data.get(1).date);
		first_status.setText(weatherBean.results.get(0).weather_data.get(1).weather);
		first_tem.setText(weatherBean.results.get(0).weather_data.get(1).temperature);
		
		second_data.setText(weatherBean.results.get(0).weather_data.get(2).date);
		second_status.setText(weatherBean.results.get(0).weather_data.get(2).weather);
		second_tem.setText(weatherBean.results.get(0).weather_data.get(2).temperature);
		
		third_data.setText(weatherBean.results.get(0).weather_data.get(3).date);
		third_status.setText(weatherBean.results.get(0).weather_data.get(3).weather);
		third_tem.setText(weatherBean.results.get(0).weather_data.get(3).temperature);
	
	}

}
實體類程式碼:

由於我使用的gson的jar包進行的資料解析,所以很方便,實體類這樣寫不用getter和setter方法,直接拿資料用省事多了

import java.util.ArrayList;


public class WeatherBean {
	public String data;
	public int error;
	public ArrayList<results> results;
	public boolean status;
	public static class results{
		public String currentCity;
		public ArrayList<index> index;
		public String pm25;
		public ArrayList<weather_data> weather_data;
		
		
	}
	public static class index{
		public String des;
		public String tipt;
		public String title;
		public String zs;
	}
	public static class weather_data{
		public String date;
		public String dayPictureUrl;
		public String nightPictureUrl;
		public String temperature;
		public String weather;
		public String wind;
	}
}

我已經將相關的類打包,可以通過該連結進行下載http://download.csdn.net/detail/u014254283/8340283