json架包:json-lib-2.4-jdk15.jar
json字符串(存在null值)转JSONObject 后return JSONObject对象的时候会报错
例如:
String str= "{"prop1":"val1", "prop2":123, "prop3":null}";
错误:
net.sf.json.JSONException: null object at net.sf.json.JSONObject.verifyIsNull(JSONObject.java:2856) at net.sf.json.JSONObject.isEmpty(JSONObject.java:2212)
解决方法:
把字符串里的null值用"" 替换(要加转义)
String data= "{"prop1":"val1", "prop2":123, "prop3":null}"; data = data.toString().replaceAll("null", """"); JSONObject json = JSONObject.fromObject(data); return json;
---------------------------------------------------------------------阿纪----------------------------------------------------------------------