//BOOK对象转JSON语言
BOOK book =newBOOK("100","一本书","我是一本书");//1. 创建Gson对象
Gson g =newGson();//2. 转换
String s = g.toJson(book);
Gson(JSON 转类)
//{"id":"100","name":"一本书","info":"我是一本书"}转BOOK对象//1. 创建Gson对象
Gson g =newGson();//2. 转换
BOOK book = g.fromJson("{\"id\":\"100\",\"name\":\"一本书\",\"info\":\"我是一本书\"}", BOOK.class);
FastJson(类转JSON)
BOOK book =newBOOK("111","我也是一本书","这也一本书");//1. 转换
String s = JSON.toJSONString(book);
FastJson (JSON转类)
//{"id":"111","info":"这也一本书","name":"我也是一本书"}//1. 转对象
BOOK book = JSON.parseObject("{\"id\":\"111\",\"info\":\"这也一本书\",\"name\":\"我也是一本书\"}", BOOK.class);//2. 转数组["一","二","三"]
List<String> strings = JSON.parseArray("[\"一\",\"二\",\"三\"]", String.class);