简体   繁体   中英

Retrofit 2.0 parsing complex api

i am using retrofit to consume weather api, before i had to deal with my own backend so i could tweak it to parse data nicely. This time i am getting json that looks something like this :

{
  "city": {
    "id": 838920,
    "name": "Ledine",
    "coord": {
      "lon": 20.34833,
      "lat": 44.802502
    },
    "country": "RS",
    "population": 0,
    "sys": {
      "population": 0
    }
  },
  "cod": "200",
  "message": 0.2644,
  "cnt": 35,
  "list": [
    {
      "dt": 1478271600,
      "main": {
        "temp": 281.58,
        "temp_min": 280.9,
        "temp_max": 281.58,
        "pressure": 1024.56,
        "sea_level": 1035.66,
        "grnd_level": 1024.56,
        "humidity": 90,
        "temp_kf": 0.68
      },
      "weather": [
        {
          "id": 800,
          "main": "Clear",
          "description": "clear sky",
          "icon": "01d"
        }
      ],
      "clouds": {
        "all": 0
      },
      "wind": {
        "speed": 3.04,
        "deg": 106.5
      },
      "rain": {},
      "sys": {
        "pod": "d"
      },
      "dt_txt": "2016-11-04 15:00:00"
    },

    {
      ......
      ......
    }
  ]
}

The model that i have made seems to complex, i am struggling with this for the last week or so. Any help would be much appreciated. Thanks!

This is Simple :
Your model have to be like this :

public class Weather implements Serializable {


public CityObj city;
public class  CityObj {
    public String name;
    public int id;
    public coordObj coord;
    public String country;
    public String population;
    public sysObj sys;
}

public class coordObj {
    public long lon;
    public long lat;

}
public class sysObj {
    public int population;
}
.
.
.

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM