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)
有人可以解释我哪里错了?我做错了什么?
要从响应中获取数据,您必须调用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中).
| 归档时间: |
|
| 查看次数: |
1538 次 |
| 最近记录: |