如何处理节点中的iOS字符串解析(日语字符)?
我在将ios字符串文件(英语->日语)上载到节点服务器进行解析时遇到问题 文件是UTF-16LE,但当解析为字符串时,字符编码会丢失字符。这可能与express使用utf8读入请求文件数据有关,这会使文件数据变形 当文件以atom/sublime w/utf16编码加载时,效果非常好 当文件以utf8格式加载时,就会发生故障如何处理节点中的iOS字符串解析(日语字符)?,ios,node.js,utf-8,utf-16,localizable.strings,Ios,Node.js,Utf 8,Utf 16,Localizable.strings,我在将ios字符串文件(英语->日语)上载到节点服务器进行解析时遇到问题 文件是UTF-16LE,但当解析为字符串时,字符编码会丢失字符。这可能与express使用utf8读入请求文件数据有关,这会使文件数据变形 当文件以atom/sublime w/utf16编码加载时,效果非常好 当文件以utf8格式加载时,就会发生故障 任何帮助都会很棒。在做了一些研究和挖掘之后 利用npm模块解析文件缓冲区应: 1) 将缓冲区解析为utf16le 2) 下变频为utf8 3) 转换成字符串 if (e
任何帮助都会很棒。在做了一些研究和挖掘之后 利用npm模块解析文件缓冲区应: 1) 将缓冲区解析为utf16le 2) 下变频为utf8 3) 转换成字符串
if (encoding === 'utf-16le') {
str = iconv.decode(buffer, 'utf16le');
body = iconv.encode(str, 'utf8').toString();
} else if (encoding === 'utf-16be') {
str = iconv.decode(buffer, 'utf16be');
body = iconv.encode(str, 'utf8').toString();
} else {
body = Buffer.concat(file.data).toString();
}
在做了一些研究和挖掘之后 利用npm模块解析文件缓冲区应: 1) 将缓冲区解析为utf16le 2) 下变频为utf8 3) 转换成字符串
if (encoding === 'utf-16le') {
str = iconv.decode(buffer, 'utf16le');
body = iconv.encode(str, 'utf8').toString();
} else if (encoding === 'utf-16be') {
str = iconv.decode(buffer, 'utf16be');
body = iconv.encode(str, 'utf8').toString();
} else {
body = Buffer.concat(file.data).toString();
}