通过API使用fetch()

骗子吧

我尝试使用fetch()从https://swapi.co/获取数据。使用此代码,我不确定,但是在chrome的“网络”部分中,我看到了我需要的数据。我该如何访问?

fetch('https://swapi.co/api/people/1/')
.then(resp => resp.json)
.then(obj => console.log(obj));
内维尔·索尔·布莱姆斯

您好,这将获取返回为json的数据

fetch('https://swapi.co/api/people/1')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(JSON.stringify(myJson));
  });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章