最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

看着变化时的错误JSON输入意外结束

运维笔记admin8浏览0评论

看着变化时的错误JSON输入意外结束

看着变化时的错误JSON输入意外结束

那么我现在要做的是得到什么已经在JSON文件和它的确切路径被修改。问题是,该JSON文件是越来越被另一个程序修饰的。每次我跑我的第二个计划修改我的JSON文件,我收到以下错误。难道有人知道为什么会出现这种情况,有一个修复? (使用程序修改JSON文件时,才会打印Thiss错误。我还可以告诉你的是,修改程序工作完全正常。)

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at getCurrent (E:\letssee2\app\testor.js:5:31)
    at FSWatcher.fs.watch (E:\letssee2\app\testor.js:11:20)
    at emitTwo (events.js:126:13)
    at FSWatcher.emit (events.js:214:7)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1364:12)

我有以下几点:

const fs = require('fs') 
const diff = require('deep-diff')

const filepath = '../temp/listings2.json' // File to watch
const getCurrent = () => JSON.parse(fs.readFileSync(filepath, {}))

let currObj = getCurrent()

fs.watch(filepath, {}, (eventType, filename) => {

const newObj = getCurrent()
const differences = diff(currObj, newObj)
var listings2 = JSON.parse(fs.readFileSync("../temp/listings2.json"))


if (differences == undefined) {
    return;
}

console.log(JSON.stringify(differences[0]["path"][0]))
console.log(JSON.stringify(differences[0]["path"][1]))
console.log(JSON.stringify(differences[0]["path"][2]))
console.log(JSON.stringify(differences[0]["path"][3]))

var path1 = String(differences[0]["path"][1])

//console.log(`\n\n${path1}\n\n`)

var fullpath = `${String(differences[0]["path"][0])}.${String(differences[0]["path"][1])}.${String(differences[0]["path"][2])}.${String(differences[0]["path"][3])}`

console.log(fullpath)

console.log(listings2[(differences[0]["path"][0])][differences[0]["path"][1]][differences[0]["path"][2]][differences[0]["path"][3]])

currObj = newObj
})
回答如下:

假设第二个程序是正确写入文件:

是否有可能修改过程中,修改事件被触发,而不是之后的第二程序写完的文件吗?

如果是这样的话,你可以偷懒而忽略了错误,并等待适当的修改,只要你是绝对肯定的其他程序将被正确地修改文件完成。

要么

你也可以去“去反弹”的检测也是如此。 more info on that here

qazxsw POI和更使qazxsw POI可以与气质,无论上班,由于不同的方式OS的构成适当的文件更改。

发布评论

评论列表(0)

  1. 暂无评论