json与object转换

//1. Convert Java object to JSON format
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(new File("c:\\user.json"), user);

//2. Convert JSON to Java object
ObjectMapper mapper = new ObjectMapper();
User user = mapper.readValue(new File("c:\\user.json"), User.class);

 

引自:http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/

你可能感兴趣的:(object)