Android 改装2-如何从复杂的JSON获取数据

Android 改装2-如何从复杂的JSON获取数据,android,json,list,gson,retrofit2,Android,Json,List,Gson,Retrofit2,我想从列表中检索数据,但我也不能。我试过这样做: double t=response.body().getList().get(0).getTemp().getMax(); 但我得到一个空指针异常 这是我的JSON 这是数据模型。如何检索列表中的数据 public class ForecastInfor { private CityBean city; private int message; private int cod; private int cnt; private List&l

我想从列表中检索数据,但我也不能。我试过这样做:

double t=response.body().getList().get(0).getTemp().getMax();
但我得到一个空指针异常

这是我的JSON

这是数据模型。如何检索列表中的数据

public class ForecastInfor {

private CityBean city;
private int message;
private int cod;
private int cnt;
private List<ListBean> list;

public CityBean getCity() {
    return city;
}

public void setCity(CityBean city) {
    this.city = city;
}

public int getMessage() {
    return message;
}

public void setMessage(int message) {
    this.message = message;
}

public int getCod() {
    return cod;
}

public void setCod(int cod) {
    this.cod = cod;
}

public int getCnt() {
    return cnt;
}

public void setCnt(int cnt) {
    this.cnt = cnt;
}

public List<ListBean> getList() {
    return list;
}

public void setList(List<ListBean> list) {
    this.list = list;
}

public static class CityBean {
    /**
     * name : Moscow
     * country : RU
     * lon : 37.6156
     * geoname_id : 524901
     * iso2 : RU
     * lat : 55.7522
     * type : city
     * population : 0
     */

    private String name;
    private String country;
    private double lon;
    private int geoname_id;
    private String iso2;
    private double lat;
    private String type;
    private int population;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public double getLon() {
        return lon;
    }

    public void setLon(double lon) {
        this.lon = lon;
    }

    public int getGeoname_id() {
        return geoname_id;
    }

    public void setGeoname_id(int geoname_id) {
        this.geoname_id = geoname_id;
    }

    public String getIso2() {
        return iso2;
    }

    public void setIso2(String iso2) {
        this.iso2 = iso2;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPopulation() {
        return population;
    }

    public void setPopulation(int population) {
        this.population = population;
    }
}

public static class ListBean {


    private int clouds;
    private TempBean temp;
    private double snow;
    private int humidity;
    private double pressure;
    private int dt;
    private double speed;
    private int deg;
    private List<WeatherBean> weather;

    public int getClouds() {
        return clouds;
    }

    public void setClouds(int clouds) {
        this.clouds = clouds;
    }

    public TempBean getTemp() {
        return temp;
    }

    public void setTemp(TempBean temp) {
        this.temp = temp;
    }

    public double getSnow() {
        return snow;
    }

    public void setSnow(double snow) {
        this.snow = snow;
    }

    public int getHumidity() {
        return humidity;
    }

    public void setHumidity(int humidity) {
        this.humidity = humidity;
    }

    public double getPressure() {
        return pressure;
    }

    public void setPressure(double pressure) {
        this.pressure = pressure;
    }

    public int getDt() {
        return dt;
    }

    public void setDt(int dt) {
        this.dt = dt;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public int getDeg() {
        return deg;
    }

    public void setDeg(int deg) {
        this.deg = deg;
    }

    public List<WeatherBean> getWeather() {
        return weather;
    }

    public void setWeather(List<WeatherBean> weather) {
        this.weather = weather;
    }

    public static class TempBean {
        /**
         * min : 261.41
         * max : 262.65
         * eve : 262.65
         * morn : 262.65
         * night : 261.41
         * day : 262.65
         */

        private double min;
        private double max;
        private double eve;
        private double morn;
        private double night;
        private double day;

        public double getMin() {
            return min;
        }

        public void setMin(double min) {
            this.min = min;
        }

        public double getMax() {
            return max;
        }

        public void setMax(double max) {
            this.max = max;
        }

        public double getEve() {
            return eve;
        }

        public void setEve(double eve) {
            this.eve = eve;
        }

        public double getMorn() {
            return morn;
        }

        public void setMorn(double morn) {
            this.morn = morn;
        }

        public double getNight() {
            return night;
        }

        public void setNight(double night) {
            this.night = night;
        }

        public double getDay() {
            return day;
        }

        public void setDay(double day) {
            this.day = day;
        }
    }

    public static class WeatherBean {
        /**
         * main : Clear
         * id : 800
         * icon : 01d
         * description : sky is clear
         */

        private String main;
        private int id;
        private String icon;
        private String description;

        public String getMain() {
            return main;
        }

        public void setMain(String main) {
            this.main = main;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getIcon() {
            return icon;
        }

        public void setIcon(String icon) {
            this.icon = icon;
        }

        public String getDescription() {
            return description;
        }

        public void setDescription(String description) {
            this.description = description;
        }
    }
}
公共类预测{
私人城市海滨城市;
私密信息;
私家侦探;
私人互联网;
私人名单;
公共城市Bean getCity(){
回归城市;
}
公共城市(城市海滨城市){
this.city=城市;
}
public int getMessage(){
返回消息;
}
公共无效设置消息(int消息){
this.message=消息;
}
公共int getCod(){
返回cod;
}
公共无效设置cod(内部cod){
this.cod=cod;
}
public int getCnt(){
返回cnt;
}
公共无效设置cnt(内部cnt){
this.cnt=cnt;
}
公共列表getList(){
退货清单;
}
公共无效集合列表(列表){
this.list=列表;
}
公共静态类CityBean{
/**
*姓名:莫斯科
*国家:俄罗斯
*朗:37.6156
*地理名称(id):524901
*iso2:RU
*拉丁美洲:55.7522
*类型:城市
*人口:0
*/
私有字符串名称;
私人国家;
私人双伦敦;
私人国际地理名称;
私有字符串iso2;
私人双lat;
私有字符串类型;
私人人口;
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共字符串getCountry(){
返回国;
}
公共国家/地区(字符串国家/地区){
这个国家=国家;
}
公共双getLon(){
返回离子;
}
公共空间设置(双设置){
this.lon=lon;
}
public int getGeoname_id(){
返回geoname\u id;
}
public void setGeoname\u id(int geoname\u id){
this.geoname\u id=geoname\u id;
}
公共字符串getIso2(){
返回iso2;
}
公共无效集合iso2(字符串iso2){
这是iso2=iso2;
}
公共双getLat(){
返回lat;
}
公共无效设置lat(双lat){
this.lat=lat;
}
公共字符串getType(){
返回类型;
}
公共void集合类型(字符串类型){
this.type=type;
}
公共整数getPopulation(){
返回人口;
}
公共人口(整数人口){
这个。人口=人口;
}
}
公共静态类ListBean{
私有云;
私人临时雇员;
私人双雪;
私人室内湿度;
私人双重压力;
私人int dt;
私人双速;
私人内部学位;
私人天气列表;
公共int getClouds(){
回归云;
}
公共云(整数云){
云=云;
}
公共TempBean getTemp(){
返回温度;
}
公共void settmp(TempBean temp){
this.temp=temp;
}
公共双getSnow(){
返雪;
}
公众假期(双雪){
这雪=雪;
}
public int get湿度(){
返回湿度;
}
公共空间设置湿度(内部湿度){
这个。湿度=湿度;
}
公众双重压力{
回流压力;
}
公共空隙设定压力(双压力){
这个。压力=压力;
}
公共整数getDt(){
返回dt;
}
公共无效设置(int dt){
这1.dt=dt;
}
公共双getSpeed(){
返回速度;
}
公共无效设置速度(双速){
速度=速度;
}
公共int getDeg(){
返回度;
}
公共空间设置度(内部度){
该度=度;
}
公共列表getWeather(){
回归天气;
}
公众天气(列出天气){
这个天气=天气;
}
公共静态类TempBean{
/**
*最低:261.41
*最高:262.65
*夏娃:262.65
*上午:262.65
*夜间:261.41
*日期:262.65
*/
私人双敏;
私人双最大值;
私人双夜;
私人双晨;
私人双人夜;
私人双日;
公共双getMin(){
返回最小值;
}
公共无效设置最小值(双最小值){
this.min=min;
}
公共双getMax(){
返回最大值;
}
公共无效设置最大值(双倍最大值){
this.max=max;
}
公共双getEve(){
返回夏娃;
}
公共无效设置eve(双eve){
this.eve=eve;
}
公共双getMorn(){
清晨归来;
}
公众假期上午(双日上午){
this.morn=morn;
}
公共双程通宵{
返回夜;
}
公众假期夜(双人夜){
这个夜晚=夜晚;
}
公共双getDay(){
回归日;
}
公众假期设定日(双日){
this.day=天;
}
}
公共静态类WeatherBean{
/**
*主要提示:清除
*身份证号码:800
*图标:01d
*描述:天空晴朗
*/
私有字符串主键;
私有int-id;
私有字符串图标;
私有字符串描述;
公共字符串getMain(){
回水总管;
}
公共void setMain(字符串main){
this.main=main;
}
公共int getId(){
返回id;
}
公共无效集合id(内部id){
this.id=id;
}
公共字符串getIcon(){
返回图标;
}
公共无效设置图标(字符串图标){
this.icon=图标;
}
公共字符串getDescription(){
返回说明;
}
公共描述
public class ForecastInfor {
    private CityBean city;
    private int message;
    private int cod;
    private int cnt;
    private List < ListBean > list;

    public CityBean getCity() {
        return city;
    }

    public void setCity(CityBean city) {
        this.city = city;
    }

    public int getMessage() {
        return message;
    }

    public void setMessage(int message) {
        this.message = message;
    }

    public int getCod() {
        return cod;
    }

    public void setCod(int cod) {
        this.cod = cod;
    }

    public int getCnt() {
        return cnt;
    }

    public void setCnt(int cnt) {
        this.cnt = cnt;
    }

    public List < ListBean > getList() {
        return list;
    }

    public void setList(List < ListBean > list) {
        this.list = list;
    }
}

public class CityBean {
    /**
     * name : Moscow
     * country : RU
     * lon : 37.6156
     * geoname_id : 524901
     * iso2 : RU
     * lat : 55.7522
     * type : city
     * population : 0
     */

    private String name;
    private String country;
    private double lon;
    private int geoname_id;
    private String iso2;
    private double lat;
    private String type;
    private int population;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public double getLon() {
        return lon;
    }

    public void setLon(double lon) {
        this.lon = lon;
    }

    public int getGeoname_id() {
        return geoname_id;
    }

    public void setGeoname_id(int geoname_id) {
        this.geoname_id = geoname_id;
    }

    public String getIso2() {
        return iso2;
    }

    public void setIso2(String iso2) {
        this.iso2 = iso2;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public int getPopulation() {
        return population;
    }

    public void setPopulation(int population) {
        this.population = population;
    }
}

public class ListBean {


    private int clouds;
    private TempBean temp;
    private double snow;
    private int humidity;
    private double pressure;
    private int dt;
    private double speed;
    private int deg;
    private List < WeatherBean > weather;

    public int getClouds() {
        return clouds;
    }

    public void setClouds(int clouds) {
        this.clouds = clouds;
    }

    public TempBean getTemp() {
        return temp;
    }

    public void setTemp(TempBean temp) {
        this.temp = temp;
    }

    public double getSnow() {
        return snow;
    }

    public void setSnow(double snow) {
        this.snow = snow;
    }

    public int getHumidity() {
        return humidity;
    }

    public void setHumidity(int humidity) {
        this.humidity = humidity;
    }

    public double getPressure() {
        return pressure;
    }

    public void setPressure(double pressure) {
        this.pressure = pressure;
    }

    public int getDt() {
        return dt;
    }

    public void setDt(int dt) {
        this.dt = dt;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    public int getDeg() {
        return deg;
    }

    public void setDeg(int deg) {
        this.deg = deg;
    }

    public List < WeatherBean > getWeather() {
        return weather;
    }

    public void setWeather(List < WeatherBean > weather) {
        this.weather = weather;
    }
}
public class TempBean {
    /**
     * min : 261.41
     * max : 262.65
     * eve : 262.65
     * morn : 262.65
     * night : 261.41
     * day : 262.65
     */

    private double min;
    private double max;
    private double eve;
    private double morn;
    private double night;
    private double day;

    public double getMin() {
        return min;
    }

    public void setMin(double min) {
        this.min = min;
    }

    public double getMax() {
        return max;
    }

    public void setMax(double max) {
        this.max = max;
    }

    public double getEve() {
        return eve;
    }

    public void setEve(double eve) {
        this.eve = eve;
    }

    public double getMorn() {
        return morn;
    }

    public void setMorn(double morn) {
        this.morn = morn;
    }

    public double getNight() {
        return night;
    }

    public void setNight(double night) {
        this.night = night;
    }

    public double getDay() {
        return day;
    }

    public void setDay(double day) {
        this.day = day;
    }
}

public static class WeatherBean {
    /**
     * main : Clear
     * id : 800
     * icon : 01d
     * description : sky is clear
     */

    private String main;
    private int id;
    private String icon;
    private String description;

    public String getMain() {
        return main;
    }

    public void setMain(String main) {
        this.main = main;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
 ForecastInfor responseBean = null;
            responseBean = (ForecastInfor) response.body();
Float t = responseBean.getList().get(0).getTemp().getMax();
public class CityBean {

private String name;
private String country;
private Float lon;
private Integer geonameId;
private String iso2;
private Float lat;
private String type;
private Integer population;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public Float getLon() {
return lon;
}

public void setLon(Float lon) {
this.lon = lon;
}

public Integer getGeonameId() {
return geonameId;
}

public void setGeonameId(Integer geonameId) {
this.geonameId = geonameId;
}

public String getIso2() {
return iso2;
}

public void setIso2(String iso2) {
this.iso2 = iso2;
}

public Float getLat() {
return lat;
}

public void setLat(Float lat) {
this.lat = lat;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Integer getPopulation() {
return population;
}

public void setPopulation(Integer population) {
this.population = population;
}

}

public class ForecastInfor {

private CityBean city;
private Integer message;
private List<ListBean> list = null;
private Integer cod;
private Integer cnt;

public CityBean getCity() {
return city;
}

public void setCity(CityBean city) {
this.city = city;
}

public Integer getMessage() {
return message;
}

public void setMessage(Integer message) {
this.message = message;
}

public List<ListBean> getList() {
return list;
}

public void setList(List<ListBean> list) {
this.list = list;
}

public Integer getCod() {
return cod;
}

public void setCod(Integer cod) {
this.cod = cod;
}

public Integer getCnt() {
return cnt;
}

public void setCnt(Integer cnt) {
this.cnt = cnt;
}

}

public class ListBean {

private Integer clouds;
private TempBean temp;
private Float snow;
private Integer humidity;
private Float pressure;
private List<WeatherBean> weather = null;
private Integer dt;
private Float speed;
private Integer deg;

public Integer getClouds() {
return clouds;
}

public void setClouds(Integer clouds) {
this.clouds = clouds;
}

public TempBean getTemp() {
return temp;
}

public void setTemp(TempBean temp) {
this.temp = temp;
}

public Float getSnow() {
return snow;
}

public void setSnow(Float snow) {
this.snow = snow;
}

public Integer getHumidity() {
return humidity;
}

public void setHumidity(Integer humidity) {
this.humidity = humidity;
}

public Float getPressure() {
return pressure;
}

public void setPressure(Float pressure) {
this.pressure = pressure;
}

public List<WeatherBean> getWeather() {
return weather;
}

public void setWeather(List<WeatherBean> weather) {
this.weather = weather;
}

public Integer getDt() {
return dt;
}

public void setDt(Integer dt) {
this.dt = dt;
}

public Float getSpeed() {
return speed;
}

public void setSpeed(Float speed) {
this.speed = speed;
}

public Integer getDeg() {
return deg;
}

public void setDeg(Integer deg) {
this.deg = deg;
}

}

public class TempBean {

private Float min;
private Float max;
private Float eve;
private Float morn;
private Float night;
private Float day;

public Float getMin() {
return min;
}

public void setMin(Float min) {
this.min = min;
}

public Float getMax() {
return max;
}

public void setMax(Float max) {
this.max = max;
}

public Float getEve() {
return eve;
}

public void setEve(Float eve) {
this.eve = eve;
}

public Float getMorn() {
return morn;
}

public void setMorn(Float morn) {
this.morn = morn;
}

public Float getNight() {
return night;
}

public void setNight(Float night) {
this.night = night;
}

public Float getDay() {
return day;
}

public void setDay(Float day) {
this.day = day;
}

}

public class WeatherBean {

private String main;
private Integer id;
private String icon;
private String description;

public String getMain() {
return main;
}

public void setMain(String main) {
this.main = main;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

}