问题描述
在杰克逊引擎试图解析来自服务器的JSON响应此错误发生。我使用Spring的Android以连载/ deserialise对象和JSON。这个问题似乎是相关的默认编码UTF-8。
是否有人知道如何告诉它应该期待的东西从UTF-8回,如UTF-16不同的引擎吗?
HttpHeaders requestHeaders = createSomeHeader();
RestTemplate restTemplate =新RestTemplate();
HttpEntity<> requestEntity =新HttpEntity<对象>(requestHeaders);
字符串URL =someurl
ResponseEntity<为MyObject []> arrayResponseEntity = restTemplate.exchange(URL,HttpMethod.GET,requestEntity,为MyObject []类。);
错误日志:
产生的原因:org.springframework.http.converter.HttpMessageNotReadableException:无法读取JSON:无效的UTF-8的高字节为0x20
在[来源:org.apache.http.conn.EofSensorInputStream@44d397b0;行:92,列:42]。嵌套例外是组织codehaus.jackson.JsonParseException:无效的UTF-8的高字节为0x20
在[来源:org.apache.http.conn.EofSensorInputStream@44d397b0;行:92,列:42]
在org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:138)
在org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:154)
在org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:74)
在org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:622)
在org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:608)
在org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:449)
在org.springframework.web.client.RestTemplate.execute(RestTemplate.java:404)
在org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:380)
... 4个
产生的原因:组织codehaus.jackson.JsonParseException:无效的UTF-8的高字节为0x20
在[来源:org.apache.http.conn.EofSensorInputStream@44d397b0;行:92,列:42]
在有机codehaus.jackson.JsonParser._constructError(JsonParser.java:1213)
在有机codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:375)
在有机codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2132)
在有机codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2139)
在有机codehaus.jackson.impl.Utf8StreamParser._de codeUtf8_3fast(Utf8StreamParser.java:1962)
JSON数据必须是EN codeD为UTF-8,UTF-16或UTF-32。该JSON德codeR可以通过确定编码检查前四个字节流的:
00 00 00 XX UTF-32BE
00 XX XX 00 UTF-16BE
XX 00 00 00 UTF-32LE
XX XX 00 00 UTF-16LE
xx月xx月xx UTF-8
这听起来像服务器是在一些非法编码编码数据(ISO-8859-1,窗口1252,等等。)
This error happens when the jackson engine tries to parse the json response from the server.I am using Spring Android to serialise/deserialise objects to and from json.This problem seems to be related to the default encoding UTF-8.
Does someone know how to tell the engine that it should expect something different from UTF-8 back such as UTF-16?
HttpHeaders requestHeaders = createSomeHeader();
RestTemplate restTemplate = new RestTemplate();
HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
String url = "someurl"
ResponseEntity<MyObject[]> arrayResponseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, MyObject[].class);
error log:
Caused by: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Invalid UTF-8 middle byte 0x20
at [Source: org.apache.http.conn.EofSensorInputStream@44d397b0; line: 92, column: 42]; nested exception is org.codehaus.jackson.JsonParseException: Invalid UTF-8 middle byte 0x20
at [Source: org.apache.http.conn.EofSensorInputStream@44d397b0; line: 92, column: 42]
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:138)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:154)
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:74)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:622)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:608)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:449)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:404)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:380)
... 4 more
Caused by: org.codehaus.jackson.JsonParseException: Invalid UTF-8 middle byte 0x20
at [Source: org.apache.http.conn.EofSensorInputStream@44d397b0; line: 92, column: 42]
at org.codehaus.jackson.JsonParser._constructError(JsonParser.java:1213)
at org.codehaus.jackson.impl.JsonParserMinimalBase._reportError(JsonParserMinimalBase.java:375)
at org.codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2132)
at org.codehaus.jackson.impl.Utf8StreamParser._reportInvalidOther(Utf8StreamParser.java:2139)
at org.codehaus.jackson.impl.Utf8StreamParser._decodeUtf8_3fast(Utf8StreamParser.java:1962)
JSON data must be encoded as UTF-8, UTF-16 or UTF-32. The JSON decoder can determine the encoding by examining the first four octets of the byte stream:
00 00 00 xx UTF-32BE
00 xx 00 xx UTF-16BE
xx 00 00 00 UTF-32LE
xx 00 xx 00 UTF-16LE
xx xx xx xx UTF-8
It sounds like the server is encoding data in some illegal encoding (ISO-8859-1, windows-1252, etc.)
这篇关于杰克逊JsonParseException:无效的UTF-8的高字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!