Android 改装错误:应为BEGIN_对象,但在第1行第58列路径$.Events.asset.suspect处为BEGIN_数组
我正在从一个请求中获取此JSON:Android 改装错误:应为BEGIN_对象,但在第1行第58列路径$.Events.asset.suspect处为BEGIN_数组,android,json,gson,retrofit,Android,Json,Gson,Retrofit,我正在从一个请求中获取此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,"suspe
{"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显示为数组时它需要一个对象?我能做些什么来修复它
编辑:漂亮的json
在您的
资产
类中,删除可疑列表
,直接使用可疑[]
数组:
public class Asset {
...
@SerializedName("suspect")
private Suspect[] suspect;
}
json不是数组,而是包含数组的对象。因此,请尝试按它所说的开始创建用于json数据访问的pojo。您是否解决了问题?