从Java字节[]>Base64>Javascript数组缓冲>Base64>byte[]
我无法将数据从Java发送到Javascript,反之亦然
到目前为止我已经试过了:
//a function I found online I use it to convert the decoded version of the java base64 byte[] to an ArrayBuffer
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));//retuns a different value than what I put into the buffer.
}
我真的不知道该怎么做了有什么想法吗
# 1 楼答案
爪哇
使用^{}
产生:
JavaScript
使用atob和btoa
产生:
注意:如果您在NodeJS中执行此操作,请查看atob包