我有一个返回以下JSON的json api:
{
"encrypted_wallet": "-GZmiQhJYnzw0FXTR6QoLryPNlgcScbfgZnmzgA35tydozNwsKWdXvIEtqWjhJIGCYdVVKB0lBKUTx-TXxHnIQn680mZIZ8lG7HNTMgprxM,"
}
在javascript方面,我将其存储在如下变量中:
$.post('api/send.php', $("#frmSend").serialize(), function (data) {
var salt, encrypted_wallet, decrypted_wallet, user_key, master_password;
if(typeof data.error === "undefined") {
encrypted_wallet_string = "-GZmiQhJYnzw0FXTR6QoLryPNlgcScbfgZnmzgA35tydozNwsKWdXvIEtqWjhJIGCYdVVKB0lBKUTx-TXxHnIQn680mZIZ8lG7HNTMgprxM,";
encrypted_wallet = data.encrypted_wallet;
console.log(encrypted_wallet);
console.log(encrypted_wallet_string);
console.log(encrypted_wallet_string.length);
console.log(encrypted_wallet.length);
encrypted_wallet = strtr(encrypted_wallet, '-_,', '+/=');
encrypted_wallet_string = strtr(encrypted_wallet, '-_,', '+/=');
encrypted_wallet = base64.decode(encrypted_wallet); // error raised
encrypted_wallet_string = base64.decode(encrypted_wallet); // works
}
});
控制台看起来像这样:
-GZmiQhJYnzw0FXTR6QoLryPNlgcScbfgZnmzgA35tydozNwsKWdXvIEtqWjhJIGCYdVVKB0lBKUTx-TXxHnIQn680mZIZ8lG7HNTMgprxM,
-GZmiQhJYnzw0FXTR6QoLryPNlgcScbfgZnmzgA35tydozNwsKWdXvIEtqWjhJIGCYdVVKB0lBKUTx-TXxHnIQn680mZIZ8lG7HNTMgprxM,
108
112
因此,由于某些原因,我从JSON api收到的字符串是4个字符的longers,因此我的base64.decode()
仅适用于粘贴在字符串中的文字。
我在这里做错了什么?