在Controller使用renderJson时,遇到以下错误
java.lang.RuntimeException at com.jfinal.json.JFinalJson.beanToJson(JFinalJson.java:333) at com.jfinal.json.JFinalJson.otherToJson(JFinalJson.java:300) at com.jfinal.json.JFinalJson.toJson(JFinalJson.java:259) at com.jfinal.json.JFinalJson.toKeyValue(JFinalJson.java:122) at com.jfinal.json.JFinalJson.mapToJson(JFinalJson.java:108) at com.jfinal.json.JFinalJson.toJson(JFinalJson.java:256) at com.jfinal.json.JFinalJson.iteratorToJson(JFinalJson.java:143) at com.jfinal.json.JFinalJson.toJson(JFinalJson.java:252) at com.jfinal.json.JFinalJson.toKeyValue(JFinalJson.java:122) at com.jfinal.json.JFinalJson.mapToJson(JFinalJson.java:108) at com.jfinal.json.JFinalJson.toJson(JFinalJson.java:256) at com.jfinal.json.JFinalJson.toJson(JFinalJson.java:205) at com.jfinal.json.MixedJsonFactory$MixedJson.toJson(MixedJsonFactory.java:37) at com.jfinal.kit.JsonKit.toJson(JsonKit.java:28) at com.thunder.web.map.MapController.query(MapController.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.jfinal.aop.Invocation.invoke(Invocation.java:73) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:74) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.jfinal.json.JFinalJson.beanToJson(JFinalJson.java:330) ... 39 more Caused by: net.sf.json.JSONException: Object is null at net.sf.json.JSONNull.isEmpty(JSONNull.java:69) ... 44 more
代码如下:jsonArray是net.sf.json的一个JSON数组。 Ret ret = Ret.ok("msg", "查询成功"); ret.put("data", jsonArray); renderJson( ret );
发现是因为JSONArray里有空的属性导致,如下红色字部分
{
"AREA": "罗湖区",
"CSIZE": -1,
"DDATETIME": "2016-10-19 16:30:55",
"LATITUDE": 22.572416,
"LONGITUDE": 114.19007,
"SIGNAL": -161,
"STREET": null
}
有什么办法吗?
项目:JFinal
renderJson(jsonString)