package jsonparsingtest;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.map.ObjectMapper;
public class JsonParsingTest {
public static class Person {
private String fullname = null;
private String org = null;
private List
emailaddrs = new ArrayList();private List
telephones = new ArrayList();private List
addresses = new ArrayList();private List
urls = new ArrayList();public String getFullname() {
return fullname;
}
public void setFullname(String fullname) {
this.fullname = fullname;
}
public String getOrg() {
return org;
}
public void setOrg(String org) {
this.org = org;
}
public List
getEmailaddrs() {return emailaddrs;
}
public void setEmailaddrs(List
emailaddrs) {this.emailaddrs = emailaddrs;
}
public List
getTelephones() {return telephones;
}
public void setTelephones(List
telephones) {this.telephones = telephones;
}
public List
getAddresses() {return addresses;
}
public void setAddresses(List
addresses) {this.addresses = addresses;
}
public List
getUrls() {return urls;
}
public void setUrls(List
urls) {this.urls = urls;
}
}
public static class Address {
private String type = null;
private String value = null;
private String format = null;
private int pref = 0;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getFormat() {
return format;
}
public void setFormat(String format) {
this.format = format;
}
public int getPref() {
return pref;
}
public void setPref(int pref) {
this.pref = pref;
}
}
public static void main(String[] args) throws Exception {
ObjectMapper om = new ObjectMapper();
// 对象就在这里读取。
Person person = om.readValue(System.in, Person.class);
// 怎么用,随便。
System.out.println(person.getFullname());
System.out.println(person.getEmailaddrs().get(0).getValue());
}
}