实体类转json 和 json转实体类

1.new JSONObject().toJSONString(rootEntity)
2. JSONObject jsonObject = JSONObject.fromObject(emp);
3.String s= JSONArray.fromObject(user).toString();

json对象中的list集合取出转为实体类集合:

List<User> userList = JSONArray.parseArray(dept.getUser(), User.class);

json转实体类

PriceListInitResult res = JSONObject.parseObject(itemStr, PriceListInitResult.class);
原文地址:https://www.cnblogs.com/xianz666/p/13322839.html