Json
JSON操作借用JSON-lib包,JSON-lib包同时依赖于以下的JAR包:
json-lib-2.4-jdk15.jar
commons-logging.jar
commons-beanutils.jar
commons-collections.jar
ezmorph.jar
/**
*json字符串转List
**/
public class Person{
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String[] args) throws Exception{
String json = "[{id:1},{id:2}]";
JSONArray jSONArray = JSONArray.fromObject(json);
List<Person> personList = JSONArray.toList(jSONArray, Person.class);
for(Personperson: personList){
System.out.println(person.getId());
}
}
}
感谢您的阅读,您的支持是我写博客动力。