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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:35:44  来源:igfitidea点击:

Why is ? changing to ?±?

javaunicode

提问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

Your stringhas a wrong encoding. It's UTF-8but you need other, uhm Latin-1? You need decode.

string的编码错误。这是UTF-8但你需要其他的,呃拉丁-1?你需要解码。

Check this

检查这个

Hope it help you.

希望对你有帮助。

回答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:

查看此讨论,它可能包含一些可以帮助您的信息: