How to read a text file and return it as a JSON object in Node JS?
问题 I have a text file. I need to read the file inside a function and return it as a JSON object. The following is throwing an error "Unexpected token V in JSON at position 0" . Server.js fs.readfile('result.txt', 'utf8', function(err,data) { if(err) throw err; obj = JSON.parse(data); console.log(obj); }); result.txt looks like the following VO1: 10 5 2 VO2: 5 3 2 I think I cannot use JSON.parse directly. How do I proceed? 回答1: Assuming the following: Every line is separated by a newline