1.相关jar包
jackson-all-1.9.0.jar
2.java2json
List<entity> list=null;
ObjectMapper mapper = new ObjectMapper();
mapper.writeValueAsString(list);
使用上述即可完成java到json的转换,若想忽略entity的某些属性值,只需在属性声明时加上@JsonIgnore
3.json2java
List<Entity>list=mapper.readValue(jsonStr,List.class);
Map m=mapper.readValue(jsonStr,Map.class);
Entity en=mapper.readValue(jsonStr,Entity.class);