tags: java
error:JSONObject[“data”] is not a JSONArray
JSONObject [ "data"] is not a JSONArray
the reason:
JSONObject json = AcceptUtil.acceptFile(req);
JSONArray data = json.getJSONArray(“data”);
data acquired JSONObject start in the front end, where the reacquisition JSONObject data array, there will be a problem, if the data value is not above error will be reported.
Solution:
used if (0! = Json.get ( "data"). ToString (). Length ()) for determining, when the length of the data array is not zero, data acquisition go array
if(0!=json.get("data").toString().length()){
JSONArray data = json.getJSONArray("data");
}
Thinking:
json first print data in the console:
json:{“data”:" “,“type”:1}
found that there is no data value, whether wanted to determine what, when there are data values, data acquired in the data again. Does that mean there is no value data to empty it, go to determine whether the data is null, then the test found that there was still the same problem. Suddenly, this time seems to be a stick awakens, null and "" is not the same, then just think of the above solution, the first json.get ( "data") converted to a string type, and then get the length, is not 0 is determined.
supplement:
before experiencing a similar problem:
net.sf.json.JSONException: JSONObject [ "name"] not found
before a solution to this problem a few days to write, inThis blogDetailed there.
Error Messages:
net.sf.json.JSONException: JSONObject[“data”] is not a JSONArray.
at net.sf.json.JSONObject.getJSONArray(JSONObject.java:1306)
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.AbstractProtocol
SocketProcessor.doRun(AprEndpoint.java:2536)
at org.apache.tomcat.util.net.AprEndpoint
Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:744)
1, import dependence 2, write test class Console output:...
JSONOBJECT, JSONARRAY Dependence` JsonObject is simple to use result ``{“name”:234,“id”:123} [{“name”:234,“id”:123}]...
The JSON used before, is a key corresponding to a value, a super simple one-to-one relationship. Now useful JSON that can be nestled in layers, taking a data so cumbersome. In fact, just like the IF e...
Why 80% of the code can not do farming architect? >>> 1, and the string is added to the collection array json 2, parsing json array (including a set of strings and) 3, imported pa...
Recently wrote an interface needs to be returned by json data format to the front. emmm, beginning met pit, because these two methods are not familiar with, yesterday afternoon to think a thought out,...
Foreword Preparation Tool Analytical thinking 1.json data format 2.jsonObject difference between jsonArray data 3. parse data 3.1 Gets the value of the website 3.2 Gets the value of basic_version in t...
Code behind JSP page uses a cyclic method to fetch data ...
The first thing to understand is that there are three packages that support string to json data, but the syntax of these two is not the same. The three packages are: org.json and json-lib; and alibaba...
JSONObject: JsonObject is just a data structure, it can be understood as a data structure in JSON format (key-valueStructure), you can use the PUT method to add an element to the JSON object. JsonObje...
content 1.jsonobject to List 1.jsonobject to List 2 // Convert MAP to JSONOBJECT JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(itemMap)); Convert the map type ItemInfo into JS...