更优雅的方式来解除code符\ u0000统一code输入流优雅、方式、code

由网友(- 我爱你比你爱我更多°)分享简介:我解析的输入流来自Facebook的未来。我使用的是类似I'm parsing an input stream coming from Facebook. I'm using something likeBufferedReader in =new BufferedReader(new InputStreamRea...

我解析的输入流来自Facebook的未来。我使用的是类似

I'm parsing an input stream coming from Facebook. I'm using something like

BufferedReader in =
    new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));

然后 in.readLine 实际上从流中读取。

And then in.readLine to actually read from the stream.

流似乎有统一code字已经连接codeD的ASCII,所以我看到的东西像 u00e4(用带有 U实际上是两个独立的ASCII字符)。现在,我在钓鱼的 u和随后的两个十六进制字节进行解码,把它们变成一个字符,并与他们替换字符串,这显然是做了最糟糕的方式。

The stream seems to have Unicode characters already encoded in ASCII, so I see things like u00e4 (with u actually being two discrete ASCII characters). Right now, I'm fishing for "u" and decoding the subsequent two hex bytes, turn them into a char and replace the string with them, which is obviously the worst way to do it.

我敢肯定有使用本地函数脱code中的特殊字符的数据流被读取(我希望它可以在InputStreamReader的层上完成的)一个冷静的方式。但如何?

I'm sure there's a cool way to use a native function to decode the special characters as the stream is being read (I was hoping it could be done on the InputStreamReader layer). But how?

推荐答案

数据格式为JSON,我没有提到(并托斯已经承担)。使用Android的JSON解析器将c中的人物会自动去$ C $正确。解析JSON自己显然是在几个层次上一个愚蠢的想法。

The data format is JSON, which I didn't mention (and which Thanatos already assumed). Using Android's JSON parser will automatically decode the characters properly. Parsing JSON yourself is obviously a dumb idea on several levels.

阅读全文

相关推荐

最新文章