因此,当我使用node .
命令初始化API时,会出现此错误:
SyntaxError: C:\Users\Andre\FishAPI\common\models\fish.json: Unexpected token } in JSON at position 945
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (internal/modules/cjs/loader.js:795:27)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at loadModelDefinition (C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:470:20)
at C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:363:21
at Array.forEach (<anonymous>)
at C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:361:8
at Array.forEach (<anonymous>)
at findModelDefinitions (C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:348:11)
at buildAllModelInstructions (C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:225:16)
at compile (C:\Users\Andre\FishAPI\node_modules\loopback-boot\lib\compiler.js:106:27)
at bootLoopBackApp (C:\Users\Andre\FishAPI\node_modules\loopback-boot\index.js:153:22)in JSON at position 945
这显然是错误所在的fish.json
:
{
"name": "Fish",
"plural": "Fish",
"base": "PersistedModel",
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"_id": {
"type": "string",
"id": true,
"required": true
},
"name": {
"type": "string",
"required": true
},
"scientific": {
"type": "string",
"required": true
},
"environment": {
"type": "string",
"required": true
},
"minClimate": {
"type": "number"
},
"maxClimate": {
"type": "number"
},
"minDepth": {
"type": "number"
},
"maxDepth": {
"type": "number"
},
"avLength": {
"type": "number"
},
"maxLength": {
"type": "number"
},
"maxWeight": {
"type": "number"
},
"maxAge": {
"type": "number"
},
"description": {
"type": "string"
},
"biology": {
"type": "string"
}
//** the space before the } below this line is where the error is? ** //
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
因此,该错误表明上述json文件中的位置945存在语法错误。我在文件中添加了注释,以显示位置945的位置。只是}之前的空格。
这里有没有人看到我为什么收到此错误?我已多次查看文件,但似乎看不到问题。