java 为什么是 ?改为 ?±?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10791649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is ? changing to ?±?
提问by NinjaBoy
I don't understand whenever I save any string that contains ? it changes to ?±. Even in the database the ? is changed to ?±.
每当我保存包含 ? 它变为?±。即使在数据库中?改为 ?±。
Examples:
例子:
- ? becomes ?±.
- Ni?o becomes Ni?±o.
- ? 变成?±。
- Ni?o 变成 Ni?±o。
I don't have any clue what causes this problem or where the problem is coming from. Please help. Thanks in advance.
我不知道是什么导致了这个问题或问题来自哪里。请帮忙。提前致谢。
采纳答案by Simon Dorociak
回答by Nathan Ryan
Character ?
(U+00F1) is encoded using UTF-8 as the two bytes 11000011 10110001
(0xC3 0xB1
).
字符?
(U+00F1) 使用 UTF-8 作为两个字节11000011 10110001
( 0xC3 0xB1
) 进行编码。
These two bytes are decoded using ISO 8859-1 as the two characters ?±
.
这两个字节使用 ISO 8859-1 作为两个字符进行解码?±
。
So, you are most likely using UTF-8 to encode the character as bytes, and ISO 8859-1 (Latin-1, as guessed by Sajmon) to decode the bytes as characters.
因此,您很可能使用 UTF-8 将字符编码为字节,并使用 ISO 8859-1(Sajmon 猜测的拉丁文 1)将字节解码为字符。
回答by óscar López
Character encoding problems, for sure. Make sure that the database, the web pages, content charset, java files, string encoding, etc. are all using the exact same encoding - for instance, UTF-8.
字符编码问题,这是肯定的。确保数据库、网页、内容字符集、java 文件、字符串编码等都使用完全相同的编码 - 例如,UTF-8。
回答by Philippe
It is a character encoding issue, you need to check if your whole stack from writer to reader is set to UTF-8.
这是一个字符编码问题,您需要检查从写入器到读取器的整个堆栈是否设置为 UTF-8。
Check out this discussion, it might contain some info to help you:
查看此讨论,它可能包含一些可以帮助您的信息: