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

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

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

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

 

 我的做法是:

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

 

相关文章:

  • 2022-12-23
  • 2021-09-30
  • 2021-05-21
  • 2021-12-12
  • 2021-04-01
  • 2021-09-18
  • 2021-08-25
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
相关资源
相似解决方案