Closed ltxhhz closed 3 years ago
I have already 👀
Can you post a sample JSON file that causes jsonfile
to give a parse error?
Can you post a sample JSON file that causes
jsonfile
to give a parse error?
Sorry, your module is perfect, and the problem is in my file. In fact, there are extra characters in my json file, which will cause an error. When I compress the json file, there is no problem. This makes me mistakenly think that it is a newline problem. Another: Can this issue be deleted? It's too embarrassing 😑
I can't delete it, but I'll close and lock it, so there will be no further comments or reactions. Don't feel bad, we all make mistakes sometimes.
我先用中文说明,因为我不知道翻译是否正确。我今天遇到个问题,读取被格式化后的json文件时,由于文件中带有换行符,会导致json解析错误,希望您可以加个替换掉文件中的换行符的步骤,我使用的是Windows系统,所以换行符是
\r\n
,我使用fs模块读取json文件后使用这段代码之后再使用JSON.parse()
就不会报错,希望您可以加到模块中I'll explain it in Chinese first, because I don't know if the translation is correct.After I met a problem today, reading is formatted json file, due to the file with a newline character, can lead to a json parse error, hope you can add a replace files line breaks in the steps, I use a Windows system, so a newline is
\r\n
, I use the fs module after reading json files after using this code reuseJSON.parse()
wouldn't be an error, I hope you can be added to the module'jsonString'.replace(/\r|\n/g,'')
这个问题报的错是这样的 Here's what's wrong with this question
UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token / in JSON at position 975