react-native - JSON Parse 错误:传递了 Unexpected EOF stacktrace null - 如何解决此错误
问题描述
constructor(props){
super(props)
this.state = {
email: '',
password: '',
showPass: false,
}
}
async signIn() {
try {
let response = await fetch(URI, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
body: JSON.stringify({
email: this.state.username,
password: this.state.password,
})
});
let responseJson = await response.json();
if (response.status = 200) {
alert('ok');
} else {
//Handle error
alert('failed')
}
} catch (error) {
console.log("error " + error);
}
}
onPress={this.signIn.bind(this)} -> 对这个按下的所有绑定
在测试此代码时,我收到此错误。我曾经将 json 作为文本响应并尝试捕获错误,但错误仍然相同,并使用 responseJson 错误调用错误,然后它显示输出,但同时请求在 url 上发布。为什么会出现此错误?
解决方案
推荐阅读
- javascript - 一个 HTML 文件/页面中的多个页面,超过 2 页
- c# - 如何使用 CoreWebView2CookieManager 在 WebView2 控件上设置 cookie
- text - 只有一个类样本时的多类文本分类
- python - 无法使用 docx 将 base64 编码图像添加到 word 文档
- docker - 从它的 IP 地址获取 docker bridge 网络中另一个节点的主机名
- django - 当 DEBUG 为 False 时,Django 框架出现服务器错误 500
- javascript - React App 在使用上下文 API 时出错
- flutter - 未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'length'。不知道原因
- javascript - React Native:在应用中显示您的 App Store 评分?(iOS/安卓)
- c# - 从数据库中检索字符串并与日期进行比较