对象转json字符串案例

测试对象与json字符串的转换

 

 json字符串转对象

Stringstr = "{\"id\":\"1001\",\"name\":\"Java入门\",\"price\":19.88,\"pnum\":100,\"category\":\"IT\",\"description\":\"Good Book\"}";

System.out.println(str);

      

//创建 "对象映射" 对象

ObjectMapper mapper = new ObjectMapper();

      

Book book = mapper.readValue(str, Book.class);

System.out.println(book);

 

posted on 2019-08-02 11:52  指尖跃动的电光,是我此生不灭的信仰  阅读(357)  评论(1编辑  收藏  举报