最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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).

发布评论

评论列表(0)

  1. 暂无评论