public class FastJsonMain {
public static void main(String[] args) {
List bookList =new ArrayList<>();
Book book =new Book();
book.setName("西游记");
book.setAuthor("罗贯中");
book.setPrice(120.0);
book.setPublishDate(new Date());
bookList.add(book);
/**
* 对象转为换字符串
*/
String bookStr = JSONObject.toJSONString(book);
System.out.println("对象转为换字符串===="+bookStr);
/**
* 对象字符串转为换Map
*/
Map map = JSONObject.parseObject(bookStr);
System.out.println("对象字符串转为换Map===="+map);
/**
* list转为字符串
*/
Book book1 =new Book();
book1.setName("aaaaaaa");
book1.setAuthor("罗贯中");
book1.setPrice(120.0);
book1.setPublishDate(new Date());
bookList.add(book1);
Book book2 =new Book();
book2.setName("西游记");
book2.setAuthor("ssssssss");
book2.setPrice(120.0);
book2.setPublishDate(new Date());
bookList.add(book2);
String listStr = JSONObject.toJSONString(bookList);
System.out.println("list转为字符串===="+listStr);
/**
* list字符串转换为Map
*/
JSONArray mapList = JSONArray.parseArray(listStr);
for (int i=0;i
JSONObject jsonObject = mapList.getJSONObject(i);
Map objectMap = JSONObject.parseObject(jsonObject.toString());
System.out.println("objectMap===="+objectMap);
}
}
}