node.js - utf-8数据怎么以汉字形式保存到txt文件中?
PHP中文网
PHP中文网 2017-04-17 15:34:57
0
2
495
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
刘奇

Are you talking about unicode character code or utf-8 character code.
If it is a unicode character code, it is similar to:

\u6c49\u5b57

Just save it like this.
But if it is

汉字

Such a character code, then you should convert it to Chinese characters and store it.

For specific coding issues, you can check out this link:
https://www.zhihu.com/questio...

黄舟

Because js has only one string type. This type is UCS-2/UTF-16. Only Blob or Buffer can truly save UTF-8 encoded data. Therefore, the GB2312 data you read through a web crawler should be directly converted into js internal strings, and then specify utf-8 encoding when saving using the fs API. In this way, the corresponding module is converted when saving.
If you want to convert it yourself, the result can only be placed in the Buffer and then written to the file.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template