美文网首页
net.sf.json.JSONException: JSONO

net.sf.json.JSONException: JSONO

作者: 牛哞哞杂记 | 来源:发表于2019-08-24 10:50 被阅读0次

    从小程序端获取openId时,出现这样的错误net.sf.json.JSONException: JSONObject[“openId”] not found

    原因:找不到openId,因为没有从小程序端获取到openId


    解决办法:可在获取openId前进行判断,若没有找到openId,就设置默认值

    //判断是否获取到openId

    if (!json.has("openId")){

    json.put("openId", "");

    }


    获取值的代码:

    JSONObject json = AcceptUtil.acceptFile(request);

    //判断是否获取到openId

    if (!json.has("openId")){

    json.put("openId", "");

    }

    String openId = json.getString("openId");


    报错信息:

    net.sf.json.JSONException: JSONObject[“openId”] not found.

    at net.sf.json.JSONObject.get(JSONObject.java:1228)

    at net.sf.json.JSONObject.getString(JSONObject.java:1353)

    at servlet.weixin.History.doPost(History.java:41)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

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

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

    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

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

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

    at filter.EncodeFilter.doFilter(EncodeFilter.java:37)

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

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

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

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

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

    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)

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

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

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

    at org.apache.coyote.AbstractProtocolAbstractConnectionHandler.process(AbstractProtocol.java:637)atorg.apache.tomcat.util.net.AprEndpointAbstractConnectionHandler.process(AbstractProtocol.java:637)atorg.apache.tomcat.util.net.AprEndpointSocketProcessor.doRun(AprEndpoint.java:2536)

    at org.apache.tomcat.util.net.AprEndpointSocketProcessor.run(AprEndpoint.java:2525)atjava.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)atjava.util.concurrent.ThreadPoolExecutorSocketProcessor.run(AprEndpoint.java:2525)atjava.util.concurrent.ThreadPoolExecutor.runWorker(UnknownSource)atjava.util.concurrent.ThreadPoolExecutorWorker.run(Unknown Source)

    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

    at java.lang.Thread.run(Unknown Source)

    相关文章

      网友评论

          本文标题:net.sf.json.JSONException: JSONO

          本文链接:https://www.haomeiwen.com/subject/sqvfectx.html