实体类转json 和 json转实体类

 

 

 

1.new JSONObject().toJSONString(rootEntity)
JSONObject.toJSONString(specPrices)//specPrices实体类
 
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);

 

posted @ 2020-07-16 15:24  红尘沙漏  阅读(8535)  评论(0编辑  收藏  举报