2016-11-05 6 views
0

私は自分のバックエンドを処理する前に、気象APIを消費するために改造を使用していますので、データをうまく解析するために調整することができます。この時間は、私はこのようになりますJSONを取得しています:Retrofit 2.0複雑なapiを解析する

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

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

私が作ったモデルが、私は先週かそこらのためにこれに苦しんでいます、複雑に思えます。どんな助けでも大歓迎です。ありがとう!

+1

問題は何ですか? – Blackbelt

+0

http://www.jsonschema2pojo.orgを使用したことがありますか? – EpicPandaForce

+0

私はして、11クラス(私はそれが正しくないと思う)私はちょうどいくつかのデータを正しくリストすることができるようにしたい。私が必要とするものは正確であるためにはcity.name、city.country、そしてリスト[0]からです.main、weather、clouds、wind、rain – vibetribe93

答えて

0

これは単純です:
あなたのモデルこのようなことする必要があります:

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

} 
関連する問題