1、将字符串或对象转换成json
JSONObject json = JSONObject.fromObject("aaa");//字符串</span>
JSONObject json = JSONObject.fromObject(对象名称.toString());
2、将list转换成json
JSONArray json = JSONArray.fromObject(list);
3、将json转换成对象
User user = (User) JSONObject.toBean(JSONObject.fromObject(需转换的对象类型字符串), User.class);
4、将json转换成对象列表
JSONArray jsonArray3 = JSONArray.fromObject(需转换的对象列表字符串);
Collection collection3 = JSONArray.toCollection(jsonArray3, User.class);
List<User> userList = (List<User>)collection3;
5、将json解析成复合类型对象, 包含List
List<GoodsPic> goodsPicList = user.getGoodsPicList();//之前已经通过方法3将json串转换成了user对象
JSONArray jsonArray1 = JSONArray.fromObject(goodsPicList);
Collection collection1 = JSONArray.toCollection(jsonArray1, GoodsPic.class);
user.setGoodsPicList((List<GoodsPic>) collection1);//这样获得的user在getGoodsPicList的时候就是获得的GoodsPic对象的列表了