问题描述
在我的Java代码中,我有以下代码段:
in my Java code I have this snippet:
String str = "\\u9601";
但我希望它是
String str = "\u9601";
代表宽字符.
有没有办法做到这一点?
Are there ways to do this?
请帮助.预先感谢.
补充:
很抱歉回答这个问题.
System.out.print("\u9601"); //this will display a Chinese character
我当前正在请求一个以JSON响应的网页(URL).如果使用"System.out.print"转储到控制台,则JSON将显示为6个可见字符 \ , u , 9 , 6 , 0 和 1 ,但日食中不包含汉字.
I am currently request a webpage(URL) which response with a JSON.If dumped to Console using "System.out.print", the JSON will turn out to be 6 visible characters \, u, 9, 6, 0 and 1,but not a Chinese character in eclipse.
所以实际上我想要的是有API可以将"\\ u9601"转换为"\ u9601",因为我不能硬编码内容的Java源来自网站.
So actually what I want is are there APIs can convert "\\u9601" to "\u9601", since I can not hard code the Java source for the contents comes from website.
推荐答案
如果您希望它是String str = "\u9601";
,请保持这种方式!
If you want it to be String str = "\u9601";
, keep it that way!
根据更新后的问题进行编辑
Apache Commons Lang API中的nofollow> StringEscapeUtils.unescapeJava 方法应为帮助:
The StringEscapeUtils.unescapeJava method in the Apache Commons Lang API should be of help:
String str = "\\u9601";
str = StringEscapeUtils.unescapeJava(str);
System.out.println(str);
这篇关于Java-从字符串评估字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!