问题
I'm having some trouble decoding some encoding char. What i need to decode is the %E9, i have a string like this D%E9bardeur and degr%E9 What i do in my java class, is the following:
try
{
System.out.println(o);// test
o = URLDecoder.decode((String) o, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
After this operation, what i get is
D�bardeur and degr�
The very same happens when i dont decode to utf-8
Any advice? thx
回答1:
%E9 is not UTF-8.
The correct way to decode this would be:
URLDecoder.decode((String) o, "ISO-8859-1")
回答2:
By %E9
, could you mean there is a byte in your string that evaluates to hex E9
? Because if so, that flags as "multibyte" in UTF-8, and there are 2 more "continuation bytes" (within the correct range) that follow.
Because remember, UTF-8 is a variable length encoding, so some code points (character values) are represented by 1 byte, some by 2, 3, etc.
If you have a string you're treating as UTF-8 and E9
is encountered, the next 2 bytes need to be in the correct range. For example, in this string, 00
, which follows E9
is not a valid continuation byte:
http://hexutf8.com/?q=0x640x650x670x720xe90x00
Here's an example where E9
in a string is followed by the correct 2 bytes:
http://hexutf8.com/?q=0xc20xa90xe90x810xaa
And the appropriate character is represented.
来源:https://stackoverflow.com/questions/18352605/decoding-e9-to-utf8-fails