js中如何将数组转化为base64encode的字符串?

数组就像这样:

[21,23,0,0,0,0,21,255,43,154,87,32,4,13,64,7,86,52,1,23,16,57,73,1]

若是btoa([21,23,0,0,0,0,21,255,43,154,87,32,4,13,64,7,86,52,1,23,16,57,73,1])
结果如下:
"MjEsMjMsMCwwLDAsMCwyMSwyNTUsNDMsMTU0LDg3LDMyLDQsMTMsNjQsNyw4Niw1MiwxLDIzLDE2LDU3LDczLDE="
atob("MjEsMjMsMCwwLDAsMCwyMSwyNTUsNDMsMTU0LDg3LDMyLDQsMTMsNjQsNyw4Niw1MiwxLDIzLDE2LDU3LDczLDE=")
"21,23,0,0,0,0,21,255,43,154,87,32,4,13,64,7,86,52,1,23,16,57,73,1"
转过去再转回来已经变成"21,23,0,0,0,0,21,255,43,154,87,32,4,13,64,7,86,52,1,23,16,57,73,1"这样的了。。


慕慕森
浏览 2609回答 1
1回答

慕勒3428872

var arry = [21, 23, 0, 0, 0, 0, 21, 255, 43, 154, 87, 32, 4, 13, 64, 7, 86, 52, 1, 23, 16, 57, 73, 1];            var str = base64Encode(arry);//转换字符串            console.log(str);            var arry2= base64Decode(str).split(',');            console.log(arry2);//转回数组            function base64Encode(input) {                var rv;                rv = encodeURIComponent(input);                rv = unescape(rv);                rv = window.btoa(rv);                return rv;            }            function base64Decode(input) {                rv = window.atob(input);                rv = escape(rv);                rv = decodeURIComponent(rv);                return rv;            }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript