2 zhangyf911028 zhangyf911028 于 2015.06.24 12:45 提问

求助: syntax error, expect {, actual error, pos 0

@RequestMapping(value="/update/{id}", method=RequestMethod.PUT)

public @ResponseBody BaseVo update(@PathVariable String id,@RequestBody UpdateRequest updateRequest){

BaseVo baseVo=new BaseVo();
// UpdateRequest updateRequest=new UpdateRequest();
// try {
// updateRequest=(UpdateRequest)BeanBind.bind(UpdateRequest.class, request);
// } catch (Exception e1) {
// e1.printStackTrace();
// }
UserRest rest=new UserRest();
rest.setId(Integer.valueOf(id));
rest.setAddress(updateRequest.getAddress());
rest.setEmail(updateRequest.getEmail());
rest.setPassWord(updateRequest.getPassWord());
rest.setUserName(updateRequest.getUserName());
rest.setCreateTime(new java.util.Date());
rest.setUpdateTime(new java.util.Date());
boolean flag=false;
try {
flag=this.userService.updateUserRest(rest);
} catch (Exception e) {
e.printStackTrace();
}
if(flag){
baseVo.setStatus("success");
baseVo.setMessage("");
}else{
baseVo.setStatus("failure");
baseVo.setMessage("");
}
return baseVo;

}

测试这个方法的时候,直接报错:

2013-11-14 14:59:54 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [spring-mvc] in context with path [/springmvcrest] threw exception [Request processing failed; nested exception is com.alibaba.fastjson.JSONException: syntax error, expect {, actual error, pos 0] with root cause
com.alibaba.fastjson.JSONException: syntax error, expect {, actual error, pos 0
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.deserialze(JavaBeanDeserializer.java:212)
at com.alibaba.fastjson.parser.deserializer.ASMJavaBeanDeserializer.parseRest(ASMJavaBeanDeserializer.java:96)
at Fastjson_ASM_UpdateRequest_1.deserialze(Unknown Source)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:513)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:244)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:220)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:179)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:327)
at com.abin.lee.rest.util.json.fastjson.FastjsonHttpMessageConverter.readInternal(FastjsonHttpMessageConverter.java:47)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:120)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:91)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:71)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:800)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
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:222)
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:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
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:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

我使用的是fastjson ,1.1.36
求大神,这个怎么破?

2个回答

yanganfu2013
yanganfu2013   2015.06.24 14:03

检查json格式. 你看看com.alibaba.fastjson.JSONException: syntax error, expect {, actual error 这句话的意思,应该是少了个"{"

spring去调用fastjson解析的时候出错了.

zhangyf911028
zhangyf911028 检查过JSON是合法的,json报错的地方有转义字符,是不是转义字符,不能识别的问题?
2 年多之前 回复
FYXjsj
FYXjsj   2015.07.28 09:44

我在android里面也碰到了, 但不是必现的 , 有些手机上会, 我问了 后台服务器,他们说 json是通过对象转的, 不应该会出现 json 不合法的情况呀

Csdn user default icon
上传中...
上传图片
插入图片