Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Express.js req.body参数数组_Arrays_Json_Node.js_Express_Routes - Fatal编程技术网

Arrays Express.js req.body参数数组

Arrays Express.js req.body参数数组,arrays,json,node.js,express,routes,Arrays,Json,Node.js,Express,Routes,我的路线有问题,我想检查req.body表单中的一些数据 我有一条路线 app.post(`/${randomQuestionsArray[0].id}`, (req, res) => { const reqValue = req.body.answer; console.log(reqValue); console.log(randomQuestionsArray[0].reqValue); }), 数据片段: const jsonContent = { "questions"

我的路线有问题,我想检查req.body表单中的一些数据

我有一条路线

  app.post(`/${randomQuestionsArray[0].id}`, (req, res) => {
const reqValue = req.body.answer;
console.log(reqValue);
console.log(randomQuestionsArray[0].reqValue);
}),

数据片段:

const jsonContent = {
  "questions": [
      {
          "id": "1",
          'slug': "566fghg6",
          "title": "post title 1",
          "desc": "This is a test desc 1",
          "answer1": {
              "answer": "test1",
              "value": true
          },
           "answer2": {
              "answer": "test2",
              "value": false
          },
           "answer3": {
              "answer": "test3",
              "value": false
          },
           "answer4": {
              "answer": "test4",
              "value": false
          }
      },
req.body.answer-给我表格etc答案的值1
但是我想从数组中获取一些数据
我创建变量:

const reqValue=req.body.answer;
randomQuestionsArray[0]。reqValue为我提供未定义的

但如果我手写: randomQuestionsArray[0]。回答1请提供数据 “答案”:“测试1”, “价值”:真实



如何将req.body放入数组参数?

如果使用常规POST方法,则可以通过以下方式解决此问题

假设您发布到“/数据记录器”


如果使用硬编码值对您有效,请使用
randomQuestionsArray[0][reqValue]
而不是
randomQuestionsArray[0].reqValue
。Thx获取帮助。它正在工作:)
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

app.post("/datalogger", function (req, res) {
    var strTitle = req.body.slug
    console.log("The title: " + strSearch);
    res.end("ok");
});