Android 端天气预报APP的实现(三)JSON解析天气数据

上一章实现了天气预报API的获取,那么,今天就来讲讲获取后的数据如何解析吧~
相比大家可以看到,解析出来的数据是json格式的,那么我们需要使用json来解析天气数据。具体实现如下:
1. 首先获取的天气数据有实时天气、今日天气和未来天气,所以我先建了三个天气类,分别为WeatherBeanNow,WeatherBeanToday,WeatherBeanForecast:
1) WeatherBeanNow.java

package com.example.zhaoxin.myweatherforecast.Bean;

/**
 * Created by zhaoxin on 17/9/16.
 * 实时天气
 */

public class WeatherBeanNow {
   

    //地区
    private String mArea;
    //pm2.5
    private String mPm25;
    //天气质量状况
    private String mQuality;
    //实时温度
    private String mTemperature;
    //实时时间
    private String mTemperatureTime;
    //天气类型
    private String mWeather;
    //风向
    private String mWindDirection;
    //风力
    private String mWindPower;
    //湿度
    private String mSd;

    public WeatherBeanNow(String mArea, String mPm25, String mQuality, String mTemperature,
                          String mTemperatureTime, String mWeather,
                          String mWindDirection, String mWindPower, String mSd) {
        this.mArea = mArea;
        this.mPm25 = mPm25;
        this.mQuality = mQuality;
        this.mTemperature = mTemperature;
        this.mTemperatureTime = mTemperatureTime;
        this.mWeather = mWeather;
        this.mWindDirection = mWindDirection;
        this.mWindPower = mWindPower;
        this.mSd = mSd;
    }

    public String getmArea() {
        return mArea;
    }

    public void setmArea(String mArea) {
        this.mArea = mArea;
    }

    public String getmTemperature() {
        return mTemperature;
    }

    public void setmTemperature(String mTemperature) {
        this.mTemperature = mTemperature;
    }

    public String getmWeather() {
        return mWeather;
    }

    public void setmWeather(String mWeather) {
        this.mWeather = mWeather;
    }

    public String getmQuality() {
        return mQuality;
    }

    public void setmQuality(String mQuality) {
        this.mQuality = mQuality;
    }

    public String getmSd() {
        return mSd;
    }

    public void setmSd(String mSd) {
        this.mSd = mSd;
    }

    public String getmPm25() {
        return mPm25;
    }

    public void setmPm25(String mPm25) {
        this.mPm25 = mPm25;
    }

    public String getmWindDirection() {
        return mWindDirection;
    }

    public void setmWindDirection(String mWindDirection) {
        this.mWindDirection = mWindDirection;
    }

    public String getmWindPower() {
        return mWindPower;
    }

    public void setmWindPower(String mWindPower) {
        this.mWindPower = mWindPower;
    }

    public String getmTemperatureTime() {
        return mTemperatureTime;
    }

    public void setmTemperatureTime(String mTemperatureTime) {
        this.mTemperatureTime = mTemperatureTime;
    }
}

2) WeatherBeanToday.java

package com.example.zhaoxin.myweatherforecast.Bean;


/**
 * Created by zhaoxin on 17/9/5.
 */

public class WeatherBeanToday {
   

    //穿衣
    private String clothes;
    //晨练指数
    private String cl;
    //化妆指数
    private String beauty;
    //紫外线指数
    private String uv;
    //中暑指数
    private String zs;
    //约会指数
    private String yh;
    //夜生活指数
    private String nl;
    //紫外线
    private String ziWaiXian;

    public String getZiWaiXian() {
        return ziWaiXian;
    }

    public void setZiWaiXian(String ziWaiXian) {
        this.ziWaiXian = ziWaiXian;
    }

    public WeatherBeanToday(String clothes, String cl, String beauty, String uv, String zs, String yh, String nl, String ziWaiXian) {
        this.clothes = clothes;
        this.cl = cl;
        this.beauty = beauty;
        this.uv = uv;
        this.zs = zs;
        this.yh = yh;
        this.nl = nl;
        this.ziWaiXian = ziWaiXian;
    }

    public String getClothes() {
        return clothes;
    }

    public void setClothes(String clothes) {
        this.clothes = clothes;
    }

    public Stri
  • 1
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值