1. 把java 对象列表转换为json对象数组,并转为字符串
JSONArray array = JSONArray.fromObject(list);
String jsonstr = array.toString();
2. 把java对象转换成json对象,并转化为字符串
JSONObject object = JSONObject.fromObject(user);
Log4jInit.ysulogger.debug(object.toString());
3.把JSON字符串转换为JAVA 对象数组
JSONArray json = JSONArray.fromObject(userStr);//userStr是json字符串
List users= (List)JSONArray.toCollection(json, User.class);
4.把JSON字符串转换为JAVA 对象
JSONObject jsonobject = JSONObject.fromObject(jsonStr);
User user= (User)JSONObject.toBean(object,User.class);