<script src="js/base64.js"></script><script>var theRequest = new Object();var url='?params=eyJhZHZhbmNlZF9wYXlfcHJpY2UiOjY2NiwiYXV0b19jb2xvciI6IuWNoeWFtumHkSIsImF1dG9fbW9kZWxfbmFtZSI6IjEuNUwg6Ieq5YqoIOe7j+WFuOWeiyIsImZpbmFsX3ByaWNlIjo1NTU1LCJpbnRlcmlvciI6IumAgOaNoui0pyIsInJlYWxfcHJpY2UiOjY2NjYsInJlZmVyX3ByaWNlIjoiMTAuMTnkuIciLCJzZWxsZXJfbW9iaWxlIjoiMTM5ODI2MTUzMDciLCJzZWxsZXJfbmFtZSI6IuiZq+WmueWmuSIsInN1Yl9icmFuZF9uYW1lIjoi5Yev6LaKIiwic3VwcGxpZXJfbmFtZSI6IuW8mOmbheWIq+WFiyIsInllYXIiOiIyMDEzIn0=';var base = new Base64();if (url.indexOf("?") != -1) { var str = url.substr(1); var strs = str.split("&"); for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]); }}var result = theRequest.params; //取到=后的值console.log(result)var strjson = base.decode(result);//base64解密console.log(strjson)var data = JSON.parse(strjson); //这里就报错 console.log(data);</script>不能转成json对象 引入了 base64解密插件 求大神帮忙下
1 回答
慕标琳琳
TA贡献1830条经验 获得超9个赞
你获取params参数时用了strs[i].split("=")的方式,导致最后base64的值的最后一位=缺失。
补充:
for (var i = 0; i < strs.length; i++) {
var splitIndex = url.indexOf("=");
theRequest[strs[i].substr(0, splitIndex - 1)] = strs[i].substr(splitIndex);
}
添加回答
举报
0/150
提交
取消