com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was B

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/79944897

今天用GSON解析数据时出现如下错误:

Android Studio:com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2

现找到如下解决办法:

链接:

http://www.oschina.net/question/1248547_121737

方法:

如果返回的是数组

这么解析

List<Dept> depts = gson.fromJson(gsonString, new TypeToken<List<Dept>>(){}.getType());  

如果返回的是数据bean这么解析即可

Dept depts = gson.fromJson(gsonString, Dept.class);


java.lang.IllegalStateException

07-10

rn源程序的一部分, 写在servlet中:rn public void logout(HttpServletRequest request, HttpServletResponse response)rn throws ServletException,IOExceptionrn HttpSession session = request.getSession();rn session.removeAttribute("username"); rn response.sendRedirect(request.getContextPath()+ "/admin/login.jsp");rn rnrnrn上面程序当执行到最后一句时出现了问题,问题输出下面 求各位高手花一分钟时间看一下,在下先谢谢了。rnrnrnjava.lang.IllegalStateExceptionrn at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)rn at com.js.servlet.adminUser.doPost(adminUser.java:32)rn at com.js.servlet.adminUser.doGet(adminUser.java:21)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rn

java.lang.IllegalStateException:

10-22

java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Tue Oct 22 19:31:09 CST 2013]; root of context hierarchyrn at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)rn at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)rn at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)rn at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:549)rn at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)rn at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)rn at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)rn at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)rn at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)rn at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)rn at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)rn at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)rn at java.util.concurrent.FutureTask.run(FutureTask.java:138)rn at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)rn at java.lang.Thread.run(Thread.java:619)rnrn是什么错误

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭