获取分配给变量的取回值

问题描述 投票:0回答:2

我想获得分配给数据变量的返回值“ responseData”

fetch('http://localhost:8080/users/update, {
          method: 'PUT',
          headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
          body: JSON.stringify({

              name:this.state.name,
              Level:this.state.activity,
              height:this.state.height,
              weight:this.state.weight
          })})
          .then((response) => {
              return response.json()   
          })
          .then((responseData) => {
            console.log(responseData)   
            this.setState({
              data:responseData
            })

          }

          );

我确实返回true,我只想将其分配给我已经尝试使用的变量

this.setState({
              data:responseData
            })

但是没用

android react-native fetch react-native-android expo
2个回答
0
投票
fetch('http://localhost:8080/users/update, {
          method: 'PUT',
          headers: {'Accept': 'application/json', 'Content-Type': 'application/json'},
          body: JSON.stringify({

              name:this.state.name,
              Level:this.state.activity,
              height:this.state.height,
              weight:this.state.weight
          })})
          .then((response) => {
              return response.json()   
          })
          .then((responseData) => {
            console.log(responseData)   
            this.setState({
  data:JSON.parse(responseData)
})

          }

          );

0
投票

@@ Asad谢谢,我弄清楚这是我的错误,尽管我尝试将json值分配给字符串变量,这是正确的代码

this.setState({
  data:JSON.parse(responseData)
})
© www.soinside.com 2019 - 2024. All rights reserved.