More elegant way to decode \ u0000 Unicode in the input stream

I am parsing the input stream from Facebook. I use something like

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

And then in.readLinefor the actual reading from the stream.

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 catching "\ u" and decoding the next two hex bytes, turning them into a char and replacing them with a string, which is obviously the worst way to do this.

I'm sure there is a cool way to use your own function to decode special characters as you read the stream (I was hoping this could be done at the InputStreamReader level). But how?

+3
source share
2 answers

The data format is JSON, which I did not mention (and which Thanatos already assumed). Using the Android JSON parser automatically decrypts the characters. Parsing JSON in itself is a dumb idea at several levels.

+5
source

"\u00e4", "\" "u" , "0", "0", "e" "4 ', , 4 (16-) . C99; " \U00XXYYZZ", 8 , 32- UTF-32 (, Unicode - 21- , 2 8 0, () 0 ).

, , Android, , , , .

+2

Source: https://habr.com/ru/post/1753825/


All Articles