【发布时间】:2014-02-17 09:26:28
【问题描述】:
我通过点击 url 得到一些 json 响应。我想用杰克逊来解析 json 响应。我尝试使用对象映射器,但出现异常。
json:
{
"contacts": [
{
"id": "c200",
"name": "ravi raja",
"email": "raja@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
},
{
"id": "c201",
"name": "Johnny Depp",
"email": "johnny_depp@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
},
]
}
pojo:
public class ContactPojo {
String name,email,gender,mobileno;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMobileno() {
return mobileno;
}
public void setMobileno(String mobileno) {
this.mobileno = mobileno;
}
}
代码:
ObjectMapper mapper=new ObjectMapper();
userData=mapper.readValue(jsonResponse,ContactPojo.class);
【问题讨论】:
-
发布您的解析代码。