net.sf.json.JSONException: JSONObject [ "data"] is not a JSONArray wrong solution

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 A b s t r a c t C o n n e c t i o n H a n d l e r . p r o c e s s ( A b s t r a c t P r o t o c o l . j a v a : 637 ) a t o r g . a p a c h e . t o m c a t . u t i l . n e t . A p r E n d p o i n t AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.AprEndpoint SocketProcessor.doRun(AprEndpoint.java:2536)
at org.apache.tomcat.util.net.AprEndpoint S o c k e t P r o c e s s o r . r u n ( A p r E n d p o i n t . j a v a : 2525 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r . r u n W o r k e r ( T h r e a d P o o l E x e c u t o r . j a v a : 1145 ) a t j a v a . u t i l . c o n c u r r e n t . T h r e a d P o o l E x e c u t o r SocketProcessor.run(AprEndpoint.java:2525) 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:744)

Intelligent Recommendation

JSONOBJECT / JSONARRAY

1, import dependence 2, write test class Console output:...

jsonObject,jsonArray

JSONOBJECT, JSONARRAY Dependence` JsonObject is simple to use result ``{“name”:234,“id”:123} [{“name”:234,“id”:123}]...

JSONObject、JSONArray

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...

JSONArray, JSONObject resolve complex json data

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...

Use JSONObject JSONArray and output data with the array of json

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,...

More Recommendation

Json data format parsing (jsonObject and JSONArray)

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...

How to get data from JSONArray and JSONObject in JSP

Code behind JSP page uses a cyclic method to fetch data  ...

String string to generate JSONObject and JSONArray 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...

Use JSONOBJECT to parse JSON data with JSonarray

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...

Data Conversion JsonObject Map List Object JsonArray

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...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top