ではない私は、HTTP要求に応答しようとしている、と私は、次のエラーを取得しています:私はそれを呼び出すのはここのNode.js - 表現 - 例外TypeError:res.jsonが機能
TypeError: req.json is not a function
です:
app.get('/', function (req, res) {
const channel_name = req.query.channel_name;
const user_name = req.query.user_name;
const text = req.query.text;
var input = text.split(" ");
if (input[0] == "move") { // Make move
game.move(user_name, channel_name, input[1], input[2], function(returnGame) {
req.json(game.getGameStatus(returnGame));
});
}
else {
var boardSize = 3;
if (input.length == 2)
boardSize = input[1];
var newGame = game.startGame(channel_name, user_name, input[0], boardSize);
res.json(game.getGameStatus(newGame));
}
});
app.listen(port);
game.moveとgame.startGameの両方がゲームと呼ばれるJSONを返します。 StartGameはJSONを作成して返しますが、moveはデータベースからJSONを読み込み、コールバックを使用してそれを返します。 コールバックからreq.jsonを呼び出すとエラーが発生しますが、StartGameでは正常に動作します。
アイデア?私はこの一日中立ち往生していて、それを理解できないようです。どんな助けでも感謝しています。
'res.json' please –