使用 response.status 反应本机时未定义 json 数据
Undefined json data while using response.status react native
在使用响应状态和响应 json 数据时,仅获取响应状态。
responseText returns undefined.Code 如下
fetch('http://mysite/check.json')
.then((response) => {
response.json();
this.setState({
xstatus: response.status
});
console.log("status_return:",this.state.xstatus);
})
.then((responseText) => {
this.setState({
xtest: responseText
});
console.log("return-------",this.state.xtest);
})
如何同时获取状态和 json 数据?
有效的代码
fetch('http://mysite/check.json')
.then(response => response.json().then(data => ({status: response.status,body:data})))
.then(responseText => {
this.setState({
xtest: responseText
});
console.log("return-------",this.state.xtest);
现在我得到了状态和数据..
在使用响应状态和响应 json 数据时,仅获取响应状态。 responseText returns undefined.Code 如下
fetch('http://mysite/check.json')
.then((response) => {
response.json();
this.setState({
xstatus: response.status
});
console.log("status_return:",this.state.xstatus);
})
.then((responseText) => {
this.setState({
xtest: responseText
});
console.log("return-------",this.state.xtest);
})
如何同时获取状态和 json 数据?
有效的代码
fetch('http://mysite/check.json')
.then(response => response.json().then(data => ({status: response.status,body:data})))
.then(responseText => {
this.setState({
xtest: responseText
});
console.log("return-------",this.state.xtest);
现在我得到了状态和数据..