我通過點擊url獲得一些json響應。我想用jackson來解析json響應。我嘗試使用對象映射器,但我收到異常。如何在android中使用Jackson分析json響應?
JSON:
{
"contacts": [
{
"id": "c200",
"name": "ravi raja",
"email": "[email protected]",
"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": "[email protected]",
"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);
發佈您的解析代碼。 – Hariharan