【问题标题】:Error sending a JSON via Axios post request in React在 React 中通过 Axios 发布请求发送 JSON 时出错
【发布时间】:2020-11-30 04:40:27
【问题描述】:

我正在尝试发送从 Formik 收到的 Json 数据。数据应该是这样的,console.log on 发送前确实是这样的:

{   config: {
       "dev_token": "merrr",
       "scs_date": "2020-02-05",
       "user_roll": "homie"
       }
}

但是,当我在 Nodejs 中控制台记录我的 req.body 时,我得到了这个:

{
  config: '{\n' +
    '  "dev_token": "merrr",\n' +
    '  "scs_date": "2020-02-05",\n' +
    '  "user_roll": "homie"\n' +
    '}'
}

为什么我得到的数据没有附加\n'?知道如何解决这个问题吗? 我提出的 Axios 请求是这样的:

 Axios.post("http://localhost:8080/pd/sources/configure/"+this.state.ModalisName,{ "config" :config })
                                     .then(result => {
                                         console.log("PUT result", result)
                                     })
                                     .catch(err =>{
                                          console.log( "PUT err", err);
                                      })

【问题讨论】:

    标签: node.js json reactjs api axios


    【解决方案1】:

    是由我在发送数据之前传入的JSON.stringify() 引起的。删除它,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-12
      • 2020-09-21
      • 2020-12-07
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多