在java中将UTF-16 unicode字符转换为UTF-8 [英] Convert UTF-16 unicode characters to UTF-8 in java
本文介绍了在java中将UTF-16 unicode字符转换为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我得到JSON时,有\\\<和\ u003e而不是<和>。我想在java中将它们转换回utf-8。任何帮助将受到高度赞赏。谢谢。
When I got JSON then there are \u003c and \u003e instead of < and >. I want to convert them back to utf-8 in java. any help will be highly appreciated. Thanks.
推荐答案
try {
// Convert from Unicode to UTF-8
String string = "\u003c";
byte[] utf8 = string.getBytes("UTF-8");
// Convert from UTF-8 to Unicode
string = new String(utf8, "UTF-8");
} catch (UnsupportedEncodingException e) {
}
引用 http://www.exampledepot.com/egs/java.lang/unicodetoutf8.html
这篇关于在java中将UTF-16 unicode字符转换为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文