我有一个字符串:'MIIciwYJKoZIhvcNAQcCoIIcfDCCHHgCAQExCzAJBgUrDgMCGgUAMIIMLAYJKoZIhvcNAQcBoIIMHQSCDBkxggwVMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATEwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBajALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDAYahMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI0NzAYAgEEAgECBBDTMQqCVP9JNijerDz8F4JOMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwGwIBAgIBAQQTDBFwb3RhdG9sYWJzLmJhbmFuYTAcAgEFAgEBBBSwSAEz57UFwfMJ0Yf7USotU0nrhDAeAgEMAgEBBBYWFDIwMTYtMTItMjBUMTg6MzY6NDNaMB4CARICAQEEFhYUMjAxMy0wOC0wMVQwNzowMDowMFowQQIBBwIBAQQ5g8RXC0VL8JCqCTi1pxOIyv/ZJRsukymatvDJGhALBUHWOplLmpsZy4vcgC1cIpOVcooNg8JcbeJDMFgCAQYCAQEEUOBY1PXnuP8l20SwT0bMOcWf9H9Xo6lxxSVDuDrOlAiHm5Pcju4eWs7iAVJOkItqhVt0gRMveJDryC1iokiqOyUC87OSM/RElc6lljTb+yOlMIIBbQIBEQIBAQSCAWMxggFfMAsCAgatAgEBBAIMADALAgIGsAIBAQQCFgAwCwICBrICAQEEAgwAMAsCAgazAgEBBAIMADALAgIGtAIBAQQCDAAwCwICBrUCAQEEAgwAMAsCAga2AgEBBAIMADAMAgIGpQIBAQQDAgEBMAwCAgarAgEBBAMCAQMwDAICBq4CAQEEAwIBADAMAgIGsQIBAQQDAgEAMBICAgavAgEBBAkCBwONfqb
除非我解码它,否则我无法理解它。但是,我已经尝试安装 base64
npm 包和 utf8
包,但它提示 _utf2.default.decode is not a function. (In \'_utf2.default.decode(bytes)\', \'_utf2.default.decode\' is undefined)
。
https://github.com/mathiasbynens/base64
https://github.com/mathiasbynens/utf8.js#utf8decodebytestring
import base64 from 'base-64';
import utf8 from 'utf8';
const bytes = base64.decode(validationData);
const text = utf8.decode(bytes); // <----- fails here
console.log("base64: ", text);
背景:尝试使用以下内容在应用程序购买中实现:https://github.com/chirag04/react-native-in-app-utils 但
receiptData
是 base64 编码的 最佳答案
如果您尝试对其进行解码并将其呈现为图像组件,您可以这样做:
const base64 = 'data:image/png;base64, *put your string here*'
<Image source={{uri: base64}} />
关于utf-8 - react native : How to decode base64 encoded string?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41252188/