我正在尝试从 hexlified 中“解码”一个 Unicode 字符串Node.js 上的二进制数据。
const convert = (from, to) => (str) => Buffer.from(str, from).toString(to);
const hexToUtf8 = convert('hex', 'utf8');
const content = hexToUtf8(data.binary)
但是当我发送以下数据时:
Sent from your Twilio trial account - ¿Cómo estás?
它被转换为
Sent from your Twilio trial account - �C�mo est�s?
二进制数据为53656e742066726f6d20796f7572205477696c696f20747269616c206163636f756e74202d20bf43f36d6f20657374e1733f
最佳答案
看起来你的字节被编码为latin1:
let data = "53656e742066726f6d20796f7572205477696c696f20747269616c206163636f756e74202d20bf43f36d6f20657374e1733f"
let b = Buffer.from(data, 'hex')
console.log(b.toString('latin1'))
打印
Sent from your Twilio trial account - ¿Cómo estás?
关于javascript - 如何将 hexlified 二进制数据转换为 unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56720061/