我是 JavaScript 和 JSON 新手,我正在尝试上传我的 NPM 包。由于某种原因,当我尝试发布它时收到此错误:
Unexpected token } in JSON at position 351 while parsing near '..."license": "ISC",
},
"bugs": {
"e..."
这是我的 JSON 文件。
{
"name": "M-P-Formulas-JS",
"version": "1.0.0",
"description": "The M-P-Formulas package for JavaScript. This package allows the user to use math and physics formulas such as the Pythagorean Theorem.",
"main": "mpformulasJS.js",
"author": {
"email": "8b21espq@gmail.com",
"name": "Jeff Lockhart",
"url": "",
"license": "ISC",
},
"bugs": {
"email": "8b21espq@gmail.com",
},
"dependencies": {
"Math": "",
},
"keywords": [
"mpformulas",
"mpformulasjs",
"m-p-formulas-js",
"math",
"physics",
"formulas",
"module",
"package",
],
}
我什至运行了npm cache clean
,但是,由于它不起作用,我可以确定我的代码是错误的。如果是这样,我该如何解决这个问题?
谢谢。
最佳答案
删除多余的逗号,因为它是关闭对象之前的最后一项。它会导致无效的 JSON。
"license": "ISC", // <--- Remove this comma
"bugs": {
"email": "8b21espq@gmail.com", // <--- Remove this comma
}
JS 对象和 JSON 是不同的。例如,这是一个有效的 JS 对象,但无效的 JSON :
bugs : {
email : "8b21espq@gmail.com",
}
有效的 JSON 为:
"bugs": {
"email": "8b21espq@gmail.com"
}
关于javascript - 解析 '..."许可证“: "ISC", 附近时,JSON 中位置 351 处的意外标记},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48063239/