我已经在javascript中将UTF 16转换为UTF 8(使用的方法:toUTF8Array)代码并从ajax调用发送代码(注意:UTF 16字符很难看,它需要我不想要的编码!) Js代码:
var compressed = LZString.compressToUTF16(uncompressed64Data);
var utf8values = toUTF8Array(compressed);
jQuery.ajax({
data :"img=+" utf8values
}
我已收到java服务器端的UTF 8代码,如下所示:
String utf8values = request.getParameter("img");
fyi,sop的结果:
utf8值:225,186,162,227,160,181,229,160,165
现在我想将代码更改为实际的UTF 16字符串?
提前致谢!
答案 0 :(得分:1)
以下内容应该有效:
String[] split = "225,186,162,227,160,181,229,160,165".split(",");
ByteBuffer bb = ByteBuffer.allocate(split.length);
Arrays.stream(split).forEach(a -> bb.put((byte)Integer.parseInt(a)));
bb.flip();
String string = Charset.forName("UTF-8").decode(bb).toString();