javascript - react-native fetch returns odd response - Stack Overflow

I'm using fetch to get some stuff from an API like this:fetch('.json').then(data => c

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 badges
Add a ment  | 

1 Answer 1

Reset to default 7

To 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

相关推荐

  • javascript - react-native fetch returns odd response - Stack Overflow

    I'm using fetch to get some stuff from an API like this:fetch('.json').then(data => c

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信