gpt4 book ai didi

android - robospice 中的 json 读取错误

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:17 25 4
gpt4 key购买 nike

Logcat 错误

07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): 06:43:48.147 Thread-9164 An exception occurred during request network execution :Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:126)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:147)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:76)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:484)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:439)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:317)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com..rb.PostRequest.loadDataFromNetwork(PostRequest.java:90)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com..rb.PostRequest.loadDataFromNetwork(PostRequest.java:1)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.octo.android.robospice.request.CachedSpiceRequest.loadDataFromNetwork(CachedSpiceRequest.java:45)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.octo.android.robospice.request.DefaultRequestRunner.processRequest(DefaultRequestRunner.java:149)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.octo.android.robospice.request.DefaultRequestRunner$1.run(DefaultRequestRunner.java:216)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at java.lang.Thread.run(Thread.java:841)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at [Source: java.util.zip.GZIPInputStream@420e4cc8; line: 1, column: 1]
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:46)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.fasterxml.jackson.databind.deser.std.StringDeserializer.deserialize(StringDeserializer.java:11)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2094)
07-30 06:43:48.135: E//DefaultRequestRunner.java:153(29678): at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.readInternal(MappingJackson2HttpMessageConverter.java:123)

这是我使用 robospice 的代码

RestTemplate restTemplate = new RestTemplate();

// Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

// Make the HTTP POST request, marshaling the request to JSON, and the response to a
String response = restTemplate.postForObject(url, message, String.class);
return response;

注意:同样的代码在一些 json 输出、一些不同类型的 json 中工作正常,我遇到了这个错误,我试图找出 json 结构的确切位置,但我觉得两者是一样的,所以我弄糊涂了,同时大声说出了这个错误的原因

最佳答案

List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
messageConverters.add(new MappingJacksonHttpMessageConverter());
restTemplate.setMessageConverters(messageConverters);

现在我得到了解决方案,但不知道如何解决,但我能理解读取 json 的问题,根据我的理解,jackson 从 json 到 string 的转换只是我更改并添加了这些转换,然后工作正常

关于android - robospice 中的 json 读取错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25029622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com