Am using Jackson JSON Processor to get details form JSON, I have the following
JSON String
{
"first_name": "first_name",
"last_name": "last",
"city": "Somewhere",
"user_user": [
{
"id": "1",
"domain": "http://google.com/"
},
{
"id": "34",
"domain": "http://so.com/"
},
{
"id": "42",
"domain": "http://ww.com/"
}
]}
UserDetails
package com.example.com;
import java.util.List;
public class UserDetails{
private String city;
private String first_name;
private String last_name;
private List<?> user_user;
public String getCity(){
return this.city;
}
public void setCity(String city){
this.city = city;
}
public String getFirst_name(){
return this.first_name;
}
public void setFirst_name(String first_name){
this.first_name = first_name;
}
public String getLast_name(){
return this.last_name;
}
public void setLast_name(String last_name){
this.last_name = last_name;
}
public List<?> getUser_user(){
return this.user_user;
}
public void setUser_user(List<?> user_user){
this.user_user = user_user;
}
}
User_user
package com.example.com;
import java.util.List;
public class User_user{
private String domain;
private String id;
public String getDomain(){
return this.domain;
}
public void setDomain(String domain){
this.domain = domain;
}
public String getId(){
return this.id;
}
public void setId(String id){
this.id = id;
}
}
Code
ObjectMapper mapper = new ObjectMapper();
UserDetails userDetails = mapper.readValue(jsonString , UserDetails.class);
System.out.println(userDetails.getFirst_name());
System.out.println(userDetails.getLast_name());
User_user userF = mapper.readValue(jsonString , User_user.class);
for(int i = 0; i < userDetails.getUser_user().size(); i++)
{
System.out.println(userF.getId());
}
From the above code am not able to get Id from
User_user
.How do I parse and get
fav_colors
if my JSON had array again.