【问题标题】:React Native - Fetch Body with Square BracketReact Native - 使用方括号获取正文
【发布时间】:2019-01-24 06:46:14
【问题描述】:

如何在 React Native 中获取带有方括号的正文/查询的 POST?

喜欢: user[email]

这是我的代码:

 fetch('url/users/sign_in/', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      'user[email]': this.state.email,
      'user[password]: this.state.password
    })
  });

【问题讨论】:

    标签: react-native


    【解决方案1】:

    user 设为对象。

    "user": {
        "email": this.state.email,
        ...
    

    【讨论】:

    • 拯救我的一天!谢谢伙计,我刚开始反应原生呵呵@gnCupo
    猜你喜欢
    • 2019-07-17
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 2022-01-19
    • 2014-07-31
    • 1970-01-01
    • 2012-06-16
    • 2022-08-24
    相关资源
    最近更新 更多