And*_*its 1 json fetch eof react-native
我希望这里有人可以帮我解决这个问题。我一直在为解决这个错误而斗争太久了。
我正在向传感器的API发出提取请求,这始终导致相同的错误:JSON解析错误:意外的EOF
我试图在网上找到答案,并尝试了很多建议,但是都没有用。
在开发环境中,我正在通过本地网络访问API。
fetchUsers(timer) {
let data = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'Bearer ' + this.state.token.access_token
}
}
fetch('http://' + this.state.ip + ':5000/api/Devices/031.01.0657/LiveState', data)
.then(response => response.json())
.then(responseJson => {
this.setState({
isLoading: false,
error: false,
userDataSource: responseJson,
refreshing: false,
time: timer
}, function () {
// If success, do something (I never make it to this part)
});
})
.catch(error => {
this.setState({
isLoading: false,
error: true
})
console.error(error);
});
}
Run Code Online (Sandbox Code Playgroud)
我当然一直在使用其他方式来查看API返回的内容:
使用API接口时得到的JSON响应:
{
"device": null,
"patient": null
}
Run Code Online (Sandbox Code Playgroud)
使用Postman客户端时得到的JSON响应:
{
"device": null,
"patient": null
}
Run Code Online (Sandbox Code Playgroud)
使用与代码中完全相同的URL。返回的JSON也作为有效JSON传递。
我想它在这一行失败了:response.json().在尝试转换响应之前,您可以查看响应的内容:
.then(response => {
console.log(JSON.stringify(response, null, 4))
return response.json())
}
Run Code Online (Sandbox Code Playgroud)
我不确定
空值
JSON中的值。也许你应该把
“空值”
希望对您有帮助!
| 归档时间: |
|
| 查看次数: |
7671 次 |
| 最近记录: |