Blackberry UTF-8 Problem

余生长醉 提交于 2019-12-13 03:47:26

问题


I have an XML handler being used in the following fashion:

SAXParserFactory.newInstance().newSAXParser().parse(new ByteArrayInputStream(response.getBytes()), myXMLHandler);

My target platform is the 4.5 JRE in order to cover a majority of the market. For some reason, this parser works on 4.5 but doesn't work on any later version of the OS. I get a Malformed UTF-8 exception generated by the parser.

Any ideas as to what would cause the different behavior? Are there characters that aren't kosher with later versions of the Blackberry JRE?


回答1:


Most likely your xml is in UTF-8 while you have response.getBytes(). String.getBytes() returns bytes for default OS encoding which is ISO-8859-1 on BB. So try to get UTF-8 bytes by calling response.getBytes("UTF-8").

I believe this is not related to OS version, but to an actual content in the response. If response contains only ASCII data, then your code would still pass OK (because those ASCII chars have the same positions in UTF-8 table). But if response has some chars beyound ASCII, then parser may fail.



来源:https://stackoverflow.com/questions/7125424/blackberry-utf-8-problem

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!