2015-03-24 2 views
1

Я получаю эту JSON обратно из запроса:

{"incidents":{"incident_bulletin":[],"asset":{"suspect":[{"suspect_id":363,"asset_id":584,"suspect_skin_color_id":-1,"suspect_height":"67","suspect_weight":"-1","suspect_hair_id":-1,"suspect_ethnicity_id":-1,"other_info":null,"suspect_direction":{"direction_id":-1,"direction":null,"direction_additional_info":""},"suspect_location":{"access_token":null,"location_id":0,"location_latitude":null,"location_longitude":null,"location_zipcode":null,"location_name":null,"location_street":null,"location_city":null,"limit":0},"suspect_age":0,"suspect_gender":null,"suspect_clothing":null,"suspect_scars":null,"suspect_tattoo":null}],"weapons":[],"vehicle":[],"images":[{"image_id":422,"asset_id":584,"image_url":"https://garbageaddress.com/copsapp_picture_29_2015_01_09_02_45_11_76?AWSAccessKeyId=AKIAJFM7HIWC32TO2KEA&Expires=1483958713&response-content-type=image%2Fjpeg&Signature=BxDtFEiDAdbZlAR4HSMi7NOxY%2BQ%3D","other_info":null}],"videos":[],"asset_text":null},"access_token":null,"incident_id":257,"incident_location_id":1307,"incident_description":"Burglary","asset_id":584,"incident_occur_datetime_start":"2015-01-09 05:42:47.00","incident_occur_datetime_end":"2015-01-09 12:42:47.00","incident_reported_datetime":"2015-01-09 10:45:58.00","incident_location":{"access_token":null,"location_id":0,"location_latitude":"40.31192","location_longitude":"-112.0059","location_zipcode":"","location_name":"","location_street":"","location_city":"","limit":0},"unread_response_count":0,"total_response_count":0,"incident_radius":0.0,"incident_location_address":"Eagle Mountain, United States.","incident_status":-1,"incident_priority":0,"incident_type":-1}} 

Я использую переоснащение, чтобы помочь положить мой JSON ответ на объекты. Я получаю эту ошибку, когда я пытаюсь сделать это:

retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 58 path $.incidents.asset.suspect 

Вот мой подозреваемый класс массив, который он жалуется:

public class SuspectList { 

    @SerializedName("suspect") 
    private Suspect[] suspect; 

А вот мой подозреваемый класс:

public class Suspect { 

    @SerializedName("suspect_id") 
    private Integer suspectID; 

    @SerializedName("asset_id") 
    private Integer assetID; 

    @SerializedName("suspect_skin_color_id") 
    private Integer skinColorID; 

    @SerializedName("suspect_height") 
    private String suspectHeight; 

    @SerializedName("suspect_weight") 
    private String suspectWeight; 

    @SerializedName("suspect_hair_id") 
    private Integer hairID; 

    @SerializedName("suspect_ethnicity_id") 
    private Integer ethnicityID; 

    @SerializedName("suspect_direction") 
    private Direction direction; 

    @SerializedName("suspect_location") 
    private Location location; 

    @SerializedName("suspect_age") 
    private Integer suspectAge; 

    @SerializedName("suspect_gender") 
    private String suspectGender; 

    @SerializedName("suspect_clothing") 
    private String suspectClothing; 

    @SerializedName("suspect_scars") 
    private String suspectScars; 

    @SerializedName("suspect_tattoo") 
    private String suspectTattoo; 

Почему он жалуется, что ожидает объект, когда JSON показывает его как массив? Любые идеи, что я могу сделать, чтобы исправить это?

EDIT: Довольно JSON enter image description here

+0

ваш JSON не является массивом, но это объект, который содержит массив. Поэтому попробуйте BEGIN_OBJECT, поскольку он говорит –

+0

Чтобы создать pojo для ваших данных json, посетите [JsonSchema2pojo] (http://www.jsonschema2pojo.org/) – Bharatesh

+0

Вы решаете проблему? –

ответ

0

В вашем Asset классе, удалить SuspectList, используйте Suspect[] массив непосредственно:

public class Asset { 
    ... 
    @SerializedName("suspect") 
    private Suspect[] suspect; 
} 
Смежные вопросы