fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

java.util.LinkedHashMap cannot be cast to com.alibaba.fastjson.JSONObject

Open MatrixCheng opened this issue 7 years ago • 2 comments

我的fastjson版本为: com.alibaba fastjson 1.2.58 对JSONArray对象做for循环 JSONArray data = respBody.getJSONArray("data"); data.forEach(item -> { String value = ((JSONObject)item).getString("value"); retResult.setData(value); }); 断点显示item为LinkedHashMap,但是编码时显示为Object 强转JSONObject对象时报错: java.util.LinkedHashMap cannot be cast to com.alibaba.fastjson.JSONObject

MatrixCheng avatar Jun 21 '19 08:06 MatrixCheng

JSONObject是请求dubbo接口返回的。如果我不请求dubbo接口而是通过HTTP或者其他方式,是可以进行强转的1.2.54版本对JSONObject的getJSONObject() getJSONArarry()方法进行了修改,增加了 对 list map的特殊处理 参考链接:http://www.mmc.xl.net.id.twowheelwerkz.com/d.m/S0/https/github.com/alibaba/fastjson/issues#start-of-content

GongSuiLi avatar Jul 12 '19 10:07 GongSuiLi

请问这个问题怎么解决,可以通过配置什么让其支持强转吗?

guopengd avatar Sep 19 '19 14:09 guopengd