2017-12-27 456 views
0

我有两个字符串: 1.记账形式\\ u0026模板 2.霍奇金\提供上门疾病如何将unicode字符转换为java中的实际字符?

我想&与” \ u0027更换\\ u0026。其中一种方式是用相应的符号替换它们的出现,但是有没有一种通用的方法来处理这个问题?

+0

请检查此链接HTTPS :// STAC koverflow.com/questions/11145681/how-to-convert-a-string-with-unicode-encoding-to-a-string-of-letters –

+0

这些字符串在哪里?他们来自哪里? –

+0

他们来自http请求的json。 –

回答

1

我的建议是Apache StringScapeUtils特别是unescapeJava方法。

网站:https://commons.apache.org/proper/commons-lang/

Maven的回购:https://mvnrepository.com/artifact/org.apache.commons/commons-lang3

enter image description here

这种方法转换UNICODE到可读文本,例如:

String stringWithUnicode; //For example "tendr\\u00e1" 
StringScapeUtils.unescapeJava(stringWithUnicode); //This call returns: Tendrá 
+0

在你的例子中,字符串文字中应该有两个'\',否则你也可以使用它自己的文字。 – bcsb1001

+0

您的代码示例应该使用双反斜杠'StringScapeUtils.unescapeJava(“\\ u00e1”);',否则字符串文字已经包含单个字符'á',由Java编译器未转义。 –

+0

答案已编辑! – Ele

相关问题