当前位置: 代码迷 >> J2EE >> json格式解析报错解决思路
  详细解决方案

json格式解析报错解决思路

热度:90   发布时间:2016-04-22 01:04:46.0
json格式解析报错
JScript code
    var carinfo ={            emptyseats : emptyseats,            carnum : carnum,            carbrand : carbrand,            driverage : driverage,            cardesc : cardesc,            isdown: isdown,            issmoking : issmoking,            iseating: iseating,            userid: userid        };        var URL = "savecarinfo.do";        $.ajax({            type : "post",// 使用post方法访问后台            dataType : "json",// 返回json格式的数据            url : URL,// 要访问的后台地址            async : "false",// 采用同步方式,必须先进行数据拉取后显示界面            contentType : "application/json;charset=utf-8",            data : {                carInfo:carinfo            }// 要发送的数据        });


后台解析总是报

Java code
net.sf.json.JSONException: A JSONObject text must begin with '{' at character 1 of carInfo[emptyseats]=1&carInfo[carnum]=&carInfo[carbrand]=&carInfo[driverage]=&carInfo[cardesc]=&carInfo[isdown]=0&carInfo[issmoking]=1&carInfo[iseating]=0&carInfo[userid]=s24f566    at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:512)    at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1096)    at net.sf.json.JSONObject._fromString(JSONObject.java:1317)    at net.sf.json.JSONObject.fromObject(JSONObject.java:185)    at net.sf.json.JSONObject.fromObject(JSONObject.java:154)    at com.carpooling.controller.CarinfoController.saveCarinfo(CarinfoController.java:57)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)    at java.lang.reflect.Method.invoke(Unknown Source)    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)    at java.lang.Thread.run(Unknown Source)
  相关解决方案