()..”异常,具体日志如下"/>
一、异常描述
通过flexjson进行字符串转换Map时报“Exception in thread "main" flexjson.JSONException: [ ]: Could not find a no-arg constructor for java.util.Map..Caused by: java.lang.NoSuchMethodException: java.util.Map.<init>()..”异常,具体日志如下
Exception in thread "main" flexjson.JSONException: [ ]: Could not find a no-arg constructor for java.util.Map@b@ at flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:53)@b@ at flexjson.ObjectBinder.bind(ObjectBinder.java:68)@b@ at flexjson.ObjectBinder.bind(ObjectBinder.java:60)@b@ at flexjson.JSONDeserializer.deserialize(JSONDeserializer.java:156)@b@ at com.xwood.publisher.util.JsonUtil.fromJson(JsonUtil.java:50)@b@ at com.xwood.publisher.util.JsonUtil.main(JsonUtil.java:108)@b@Caused by: java.lang.NoSuchMethodException: java.util.Map.<init>()@b@ at java.lang.Class.getConstructor0(Class.java:2715)@b@ at java.lang.Class.getDeclaredConstructor(Class.java:1987)@b@ at flexjson.factories.ClassLocatorObjectFactory.instantiate(ClassLocatorObjectFactory.java:28)
二、解决方法
通过flexjson工具类实现字符串及对象互转(工具类转换示例),之前转换示例
String ssss="{\"CONTENT_TYPE\":\"0\",\"CHANNLE_ID\":\"9386\",\"CONTENT_ID\":\"157756\",\"OBJECT_ID\":\"157756\",\"TITLE\":\"test8\"}";@b@Map<String,String> ps=JsonUtil.fromJson(ssss, Map.class);
改为如下问题解决了
String ssss="{\"CONTENT_TYPE\":\"0\",\"CHANNLE_ID\":\"9386\",\"CONTENT_ID\":\"157756\",\"OBJECT_ID\":\"157756\",\"TITLE\":\"test8\"}";@b@Map<String,String> ps=JsonUtil.fromJson(ssss);