使用 fetch 时:
fetch(REQUEST_URL, {
method: 'get',
dataType: 'json',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then((response) =>
{
response.json() // << This is the problem
})
.then((responseData) => { // responseData = undefined
console.log(responseData);
});
}).catch(function(err) {
console.log(err);
})
.done();
以下作品有效,你知道为什么吗? :
JSON.parse(response._bodyText)
最佳答案
链接响应应该更像这样,特别是 response.json
部分。那么你应该得到一个 Object
回到 console.log
.
.then(response => response.json())
.then(response => {
console.log(response)
}
关于react-native - 获取 response.json() 给出 responseData = undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33237200/