Haf*_*eem 3 json http-post react-native
这是我的功能
不知道问题出在哪里
fetchData() {
fetch(REQUEST_URL, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
Request : 'menu',
active : '1',
})
}).then((response) => response.json())
.then((responseData) => {
this.setState({
menu: responseData.Response,
});
})
.catch((error) => {
console.warn('error',error);
})
.done();
}
Run Code Online (Sandbox Code Playgroud)
请指出功能上的问题
发生该错误是因为您的响应无法转换为JSON格式。可能由于错误的标头,响应正文或基于服务器的其他各种原因而发生此问题。由于显然响应不一致,因此,方法是在尝试将响应转换为JSON之前执行服务器响应的其他验证。
您可以通过以下方式来实现:
.then((response) => response.json())
Run Code Online (Sandbox Code Playgroud)
与
.then((response) => response.json())
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7402 次 |
| 最近记录: |