黑莓UTF-8的问题 [英] Blackberry UTF-8 Problem

查看:271
本文介绍了黑莓UTF-8的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的时尚正在使用的XML处理程序:

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

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

我的目标平台是4.5 JRE,以覆盖广大的市场。出于某种原因,这个解析器的工作4.5,但在操作系统的更新版本不起作用。我得到由分析器生成格式错误的UTF-8例外。

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.

任何想法什么会导致不同的行为呢?是否有不犹太更高版本的黑莓JRE?

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

推荐答案

最有可能你的XML是UTF-8,而你有 response.getBytes()。 String.getBytes()返回默认的操作系统编码是BB ISO-8859-1字节。因此,试图通过调用来获得UTF-8字节 response.getBytes(UTF-8)

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").

我相信这是不相关的操作系统版本,但在响应中的实际内容。如果响应只包含ASCII数据,那么你的code仍然会通过正常(因为这些字符的ASCII在UTF-8表相同的位置)。但是,如果响应有一些字符的ASCII远超过,则解析器可能会失败。

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.

这篇关于黑莓UTF-8的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆