首页 > 解决方案 > 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 上发布。为什么会出现此错误?

标签: react-native

解决方案


推荐阅读