Blackberry UTF-8 Problem
I have an XML handler being used in the following fashion:
SAXParserFactory.n开发者_如何学CewInstance().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?
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.
精彩评论