react-native fetch返回奇数响应

Hie*_*ero 5 javascript fetch react-native

我正在使用fetch从这样的API中获取一些东西:

fetch('http://facebook.github.io/react-native/movies.json')
        .then(
            data => console.log(data),
            error => console.log(error)
        )
Run Code Online (Sandbox Code Playgroud)

但我得到的是以下对象,而不是实际数据

_bodyBlob: Blob
_bodyInit: Blob
headers: Headers
ok: true
status: 200
statusText: undefined
type: "default"
url: "http://facebook.github.io/react-native/movies.json"
Run Code Online (Sandbox Code Playgroud)

有人可以解释我哪里错了?我做错了什么?

Kra*_*ffs 7

要从响应中获取数据,您必须调用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);
  });
Run Code Online (Sandbox Code Playgroud)

(假设响应在json中).

  • 这是行不通的。我几乎不愿看到邮寄要求的身体反应。它适用于邮递员,但不适用于本机应用程序 (2认同)