繁体   English   中英

Retrofit 2.0解析复杂的api

[英]Retrofit 2.0 parsing complex api

在我不得不处理自己的后端之前,我正在使用改造来消耗天气api,以便可以对其进行调整以很好地解析数据。 这次我得到的json看起来像这样:

{
  "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"
    },

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

我制作的模型似乎很复杂,在上个星期左右,我一直在为此苦苦挣扎。 任何帮助将非常感激。 谢谢!

这很简单:
您的模型必须是这样的:

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;
}
.
.
.

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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