json轉換問題

我這樣parse userInfo = JsonKit.parse(json.toString(),UserInfo.class);會噴錯

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

at com.jfinal.aop.Invocation.invoke(Invocation.java:87)

at com.demo.blog.BlogInterceptor.intercept(BlogInterceptor.java:14)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.demo.common.config.AuthInterceptor.intercept(AuthInterceptor.java:16)

at com.jfinal.aop.Invocation.invoke(Invocation.java:67)

at com.jfinal.core.ActionHandler.handle(ActionHandler.java:74)

at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)

at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)

at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

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:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at com.jfinal.aop.Invocation.invoke(Invocation.java:73)

... 24 more

Caused by: java.lang.NoClassDefFoundError: com/alibaba/fastjson/JSON

at com.jfinal.json.FastJson.parse(FastJson.java:42)

at com.jfinal.kit.JsonKit.parse(JsonKit.java:32)

at com.demo.blog.BlogController.add(BlogController.java:43)

... 29 more

Caused by: java.lang.ClassNotFoundException: com.alibaba.fastjson.JSON

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1313)

at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1164)


评论区

lyh061619

2017-01-09 14:32

看你的问题,错误在这里:Caused by: java.lang.ClassNotFoundException: com.alibaba.fastjson.JSON

at 少引入个FastJson包,把这个包加上去就可以了。

jerry1216

2017-01-09 14:41

@lyh061619 但lib裡不是本來就有包fastjson-1.2.6.jar 我還要再import一次?

jerry1216

2017-01-09 14:50

@lyh061619 果然還真的要加FastJson包

jerry1216

2017-01-09 15:11

@lyh061619 renderJson可以放List的物件嗎?

lyh061619

2017-01-09 15:20

@jerry1216 多看手册下,在第三章的3.9小点上说明。

JFinal

2017-01-09 20:58

@jerry1216 renderJson 有很多重载方法,功能不一,建议看看手册,此外,renderJson可以支持已被转换成 String的 json 内容,所以,当无法满足需求时,你可以使用任何第三方工具,预先将 json 数据转换好,然后这样做:

String jsonContent = MyJsonTook.toJson(...);
renderJson(jsonContent);

热门反馈

扫码入社