【发布时间】:2020-11-03 11:10:27
【问题描述】:
我有一个文本文件,其中包含写入其中的多个对象。我需要在文本文件中将fetch 的所有对象都设置为JSON。我该怎么办?
我的文件中的数据:
{"events":[...] },{"events":[....]},{},{}....
我试着把它读成:
fs.readFile('gcyoi6.txt', function (err, data) {
if (err) throw err;
data =data.toString();
console.log(data)
});
它将数据作为字符串提供。但我需要它作为JSON 对象
提前致谢!
【问题讨论】:
-
const obj = JSON.parse( jsonString ); -
@ippi SyntaxError: Unexpected token , in JSON
标签: javascript node.js json reactjs file-handling