我正在尝试使用MERN堆栈构建一个小型社交网站。我已经安装了Nodejs和一些依赖项。当我尝试使用Postman发布数据时(这在登录页面上——必须输入姓名、电子邮件和密码(,终端会显示此错误,Postman也会显示错误。这里的问题是什么?
> SyntaxError: Unexpected token n in JSON at position 1
> at JSON.parse (<anonymous>)
> at parse (C:UsersASUSDocumentsGitHubdevconnectornode_modulesbody-parserlibtypesjson.js:89:19)
> at C:UsersASUSDocumentsGitHubdevconnectornode_modulesbody-parserlibread.js:121:18
> at invokeCallback (C:UsersASUSDocumentsGitHubdevconnectornode_modulesraw-bodyindex.js:224:16)
> at done (C:UsersASUSDocumentsGitHubdevconnectornode_modulesraw-bodyindex.js:213:7)
> at IncomingMessage.onEnd (C:UsersASUSDocumentsGitHubdevconnectornode_modulesraw-bodyindex.js:273:7)
> at IncomingMessage.emit (events.js:387:35)
> at endReadableNT (internal/streams/readable.js:1317:12)
> at processTicksAndRejections (internal/process/task_queues.js:82:21)
我正在发送以下令牌:
{name : "John Doe", email : "example@gmail.com, password : "somepassword"}
您应该将键放在引号中。不管意外的令牌是什么,这个错误通常意味着您试图发送的不是有效的JSON。试试这个:
{"name": "John Doe", "email": "example@gmail.com", "password": "somepassword"}