小编Fas*_*619的帖子

从Java byte [] - > Base64 - > Javascript ArrayBuffer - > 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.
}
Run Code Online (Sandbox Code Playgroud)

我真的不知道怎么回事这个想法?

javascript java audio

4
推荐指数
1
解决办法
3306
查看次数

标签 统计

audio ×1

java ×1

javascript ×1