当我在node.js中读取JSON文件时,非英文字符显示为“?”而不是原始人物 流的结果已经在错误的字符集中。
var fs = require('fs');
var path = require('path');
var stream = fs.createReadStream(path.join(__dirname,'../data.json'), 'utf8');
stream.on('error', function (error) {
response.status(500).send({ msg: error.message });
})
stream.pipe(response);
}
}
文件示例:
{
data: [
{"id":"111","name":"Dr. Per Änglund","phone":"7350-01794"},
{"id":"22","name":"Lars Änglund","phone":"1942-463945"}
]
}