gpt4 book ai didi

javascript - req.body.data 在expressjs中未定义

转载 作者:太空宇宙 更新时间:2023-11-04 03:29:43 26 4
gpt4 key购买 nike

我是 Nodejs 和 Express JS 的新手。我正在尝试使用 postman 将 json 对象发送到我的 nodejs 应用程序。 PFB 我的应用程序代码

var express = require("express");
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());

app.post("/game",function(req,res){
console.log(req.body);

console.log(req.body.gameId);
//var body = req.body;
//game.addGame(req,res,body);

});


app.listen(setting.port);
console.log(`The app is listening to port ${setting.port}`);

我使用 postman 发送以下 json 对象

{
"gameID": 4,
"gameLevel": 3,
"gameImage": "/3wewe/wewrw",
"gameName": "Game2",
"waitTimeForWinny": 30,
"totalTime": 31,
"orderSequence": 1,
"maxPoints": 10
}

然后我在控制台中得到以下输出。

{ gameID: 4,
gameLevel: 3,
gameImage: '/3wewe/wewrw',
gameName: 'Game2',
waitTimeForWinny: 30,
totalTime: 31,
orderSequence: 1,
maxPoints: 10 }
undefined

json 对象位于 req.body 中。但我无法使用 req.body.gameId 从中提取字段

请帮我解决这个问题。

最佳答案

您将 id 属性作为 gameID 传递,但您正在记录 gameId(注意小写的 d)

关于javascript - req.body.data 在expressjs中未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39749963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com