我遇到了从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.
}
我真的不知道该怎么做了,还有什么想法吗?