我想获得分配给数据变量的返回值“ 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
})
但是没用
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)
})
}
);
@@ Asad谢谢,我弄清楚这是我的错误,尽管我尝试将json值分配给字符串变量,这是正确的代码
this.setState({
data:JSON.parse(responseData)
})