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());
}
}

}

 

posted @ 2016-06-30 12:00  N神3  阅读(152)  评论(0编辑  收藏  举报