首页 > Web开发 > 详细

json串转对象和对象列表

时间:2021-06-25 17:12:53      阅读:16      评论:0      收藏:0      [点我收藏+]
1.json串转对象-JSONObject.parseObject

R r= platformApi.getUserinfo();
Userinfo user = JSONObject.parseObject(JSONObject.toJSONString(r.getData()),Userinfo.class);


R如下:
public class R<T> {
    private String code;
private boolean success;
private String errorMsg;
private T data;
get、set方法省略。
}

r.getData()不是json串,需要通过JSONObject.toJSONString()转化为json串。
2.json串转对象列表-JSONObject.parseArray
R menusR = platformApi.getEnterpriseMenuList(enterpriseMenu);
List<EnterpriseMenu> menus = JSONObject.parseArray(JSONObject.toJSONString(menusR.getData()),EnterpriseMenu.class);

注意:
JSONObject导包为import com.alibaba.fastjson.JSONObject;


json串转对象和对象列表

原文:https://www.cnblogs.com/nuomm/p/14931246.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!