【解决方案】Resolved [com.alibaba.fastjson.JSONException: exepct '[', but string, pos

时间:2020-02-26 16:09:50   收藏:0   阅读:658

使用fastjson,将字符串转数组时抛异常:

Resolved [com.alibaba.fastjson.JSONException: exepct ‘[‘, but string, pos

如下图中所示,result.getData()是一个字符串,我希望将它转为一个数组

技术分享图片

 

 我的做法是:

String res = JSON.toJSONString(result.getData());
List<TFDepartment> departmentList = JSONArray.parseArray(res, TFDepartment.class);

所以抛异常了:Resolved [com.alibaba.fastjson.JSONException: exepct ‘[‘, but string, pos

解决方案如下:

String res = JSON.toJSON(result.getData()).toString();
List<TFDepartment> departmentList = JSONArray.parseArray(res, TFDepartment.class);

 

原文:https://www.cnblogs.com/miaoying/p/12367114.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!