为什么body-parser.json()不起作用?显示语法错误:JSON 中意外的令牌 } 在 JSON.parse () 的位置 100<anonymous>



请向我解释我在哪里做错。为什么我的身体不以JSON格式解析

i m使用Postman作为我的邮政请求...(下面提到标题类型(

[{" key":" content-type"," name":" content-type"," value":" application/json"," description":","," type":" text"}]

谢谢您的帖子,感谢您的贡献

const express=require('express');
const bodyParser=require('body-parser');
const app=express();
const port= process.env.PORT || 3002;
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));

app.post('/send',(req,res)=>{
    res.json(req.body);
})
app.listen(port,()=>{
    console.log(`listing to port ${port}`)
});
SyntaxError: Unexpected token } in JSON at position 100
    at JSON.parse (<anonymous>)
    at parse (C:UsersDeepak DasDesktopnode testtestnode_modulesbody-parserlibtypesjson.js:89:19)
    at C:UsersDeepak DasDesktopnode testtestnode_modulesbody-parserlibread.js:121:18
    at invokeCallback (C:UsersDeepak DasDesktopnode testtestnode_modulesraw-bodyindex.js:224:16)
    at done (C:UsersDeepak DasDesktopnode testtestnode_modulesraw-bodyindex.js:213:7)
    at IncomingMessage.onEnd (C:UsersDeepak DasDesktopnode testtestnode_modulesraw-bodyindex.js:273:7)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

以防万一有人遇到此问题。我认为我在邮递员的主体中犯了一个错误, { "comment": "Some random comment", "author": "Lucky", }。错误是作者末尾的最后一个逗号(,(的结果。因此,我要做的就是进行更正,一切都奏效了。

此消息:Unexpected token ** } ** in JSON at position 100表示} 字符位于错误的位置

最新更新