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


使用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);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM