I'm using fetch to get some stuff from an API like this:
fetch('.json')
.then(
data => console.log(data),
error => console.log(error)
)
But what I get back is the following object, not the actual data
_bodyBlob: Blob
_bodyInit: Blob
headers: Headers
ok: true
status: 200
statusText: undefined
type: "default"
url: ".json"
Can someone explain me whats wrong? I'm doing something wrong?
I'm using fetch to get some stuff from an API like this:
fetch('http://facebook.github.io/react-native/movies.json')
.then(
data => console.log(data),
error => console.log(error)
)
But what I get back is the following object, not the actual data
_bodyBlob: Blob
_bodyInit: Blob
headers: Headers
ok: true
status: 200
statusText: undefined
type: "default"
url: "http://facebook.github.io/react-native/movies.json"
Can someone explain me whats wrong? I'm doing something wrong?
Share Improve this question edited Mar 18, 2022 at 8:46 VLAZ 29.2k9 gold badges63 silver badges84 bronze badges asked Jul 6, 2016 at 13:42 HieroHiero 2,2057 gold badges30 silver badges48 bronze badges1 Answer
Reset to default 7To get the data from the response you have to call data.json();
Example:
fetch('http://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((data) => {
console.log(data);
})
.catch((error) => {
console.log(error);
});
(Assuming the response is in json).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745399861a4626049.html
评论列表(0条)