我正在解析下面的json并且无法正确解决问题。它表示用户没有START_ARRAY令牌。
{
"code": "true",
"response": [
{
"strId": "lorem123",
"intIdx": "176",
"strName": "lorem",
"strAddr": "565 lorem ipsum dolor",
"strMobile": "010-5882-7979",
"strBirth": "1948-01-30",
"intExperience": "4",
"strJob": "",
"strJob1": "sample job1",
"strJob2": "sample job2",
"strJob3": "sample job3",
"strFile": "",
"isForeigner": "Y",
"strEmailId": "loremid",
"strEmailSv": "google.com",
"strGender": "M",
"isCarSupport": "Y"
}
]
}
我正在使用此代码映射它:
ObjectMapper mapper = new ObjectMapper();
Response response = mapper.readValue(url, Response.class);
return response.getUser();
我的Response类看起来像这样:
public class Response {
@JsonProperty("code")
public boolean isOkay;
@JsonProperty("response")
public List<User> user;
//getters and setters
}
我的User类看起来像这样:
public class User {
@JsonProperty("strId")
public String id;
@JsonProperty("intIdx")
public int index;
@JsonProperty("strName")
public String name;
//... other fields
//getters and setters
}
答案 0 :(得分:0)
奇怪,如果我设置
public List<User> user;
到
public User[] user;
效果很好..