我已经写了一大段代码。
function getScreenshotObj (pathToFirstFile) {
return new Promise ((resolve,reject) =>{
console.log("Path to temp dir : " + pathToFirstFile)
fs.readFile(pathToFirstFile,function(err,fileContents){
if (err) {
return reject(err)
}
else{
screenshotObject = JSON.parse(fileContents)
obj = {pathToFirstFile : pathToFirstFile , screenshotObject:screenshotObject ,accesstoken : accesstoken}
return resolve(obj)
}
})
})
}它在JSON.parse()给了我一个错误。未捕获的语法错误:JSON.parse()处的意外输入结束.I使用在线JS语法检查了语法,他们说代码在语法上是有效的。请纠正我哪里弄错了。
发布于 2017-04-23 21:35:16
对于fs.readFile,如果不指定编码,则返回原始数据缓冲区。source
更改:
fs.readFile(pathToFirstFile, function(err, fileContents) {至
fs.readFile(pathToFirstFile, 'utf8', function(err, fileContents) {https://stackoverflow.com/questions/43571382
复制相似问题