# node 字符串使用 utf8 编码

let str = JSON.stringify(json);
const encoder = new TextEncoder();
const uint8 = encoder.encode(str);
const buffer = Buffer.from(uint8);
str = buffer.toString('utf8');
console.log(str)
console.log(uint8.byteLength) // 字符串长度使用 byteLength
1
2
3
4
5
6
7
上次更新: 12/7/2023, 6:23:35 PM