在java中将UTF-16 unicode字符转换为UTF-8

当我得到JSON然后有\ u003c和\ u003e而不是。 我想在java中将它们转换回utf-8。 任何帮助将受到高度赞赏。 谢谢。

 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中将字符串转换为UTF8字节数组

祝你好运,M

您可以尝试将字符串转换为字节数组

 byte[] utfString = str.getBytes("UTF-8") ; 

并通过指定UTF-8编码将其转换回字符串对象

 str = new String(utfString,"UTF-8") ;