意外的字符('A'(代码65)):期望双引号来启动字段名称

时间:2013-11-15 10:03:01

标签: java json spring spring-mvc

您好我正在使用Spring rest Template来命中POST API,并且工作正常。

问题是当我在MockRestServiceServer中使用它时。

我创建了一个MockRestServiceServer实例:

mockServer = MockRestServiceServer.createServer(restTemplate);

并添加了预期的请求URL和响应i,e:

mockServer.expect(requestTo(URL)).andExpect(method(HttpMethod.POST))
    .andRespond(withSuccess(Response,MediaType.APPLICATION_JSON));

当我尝试使用JSON正文

命中特定的POST网址时
{"AppName":{"Value":"Google"}}

我收到错误

org.springframework.http.converter.HttpMessageNotReadableException: 
Could not read JSON: Unexpected character ('A' (code 65)): was expecting double-quote 
to start field name  at 
[Source: java.io.ByteArrayInputStream@5473b9e; line: 1, column: 3]; 
nested exception is org.codehaus.jackson.JsonParseException: Unexpected character 
('A' (code 65)): was expecting double-quote to start field name  at 
[Source: java.io.ByteArrayInputStream@5473b9e; line: 1, column: 3]  at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal
(MappingJacksonHttpMessageConverter.java:127) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]     at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]    
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:81) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]    
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:446) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]   
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]     
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]

任何人都可以帮助我,我在这里缺少什么?

0 个答案:

没有答案