问题描述
我正在尝试使用 MERN 堆栈构建一个小型社交网站。我已经安装了 Nodejs 以及一些依赖项。当我尝试使用 Postman 发布数据时(这是在登录页面上 - 必须输入姓名、电子邮件、密码),终端显示此错误,Postman 也显示错误。这里有什么问题?
> SyntaxError: Unexpected token n in JSON at position 1
> at JSON.parse (<anonymous>)
> at parse (C:\Users\ASUS\Documents\GitHub\devconnector\node_modules\body-parser\lib\types\json.js:89:19)
> at C:\Users\ASUS\Documents\GitHub\devconnector\node_modules\body-parser\lib\read.js:121:18
> at invokeCallback (C:\Users\ASUS\Documents\GitHub\devconnector\node_modules\raw-body\index.js:224:16)
> at done (C:\Users\ASUS\Documents\GitHub\devconnector\node_modules\raw-body\index.js:213:7)
> at IncomingMessage.onEnd (C:\Users\ASUS\Documents\GitHub\devconnector\node_modules\raw-body\index.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"}