首页 > 解决方案 > 获取 newsapi 数据

问题描述

我尝试使用https://newsapi.org新 api

fetch(new Request('https://newsapi.org/v2/top-headlines....')).then(function(response) {
    var json = response.json();
    console.log(json);//It gives 'Promise {<resolved>: {…}}'
    console.log(json.Promise//not work
    console.log(json.Promise['[[promiseValue]]']);//not work
});

如何获得 json.Promise['']['[[promiseValue]]']?感谢您的回复

标签: javascript

解决方案


请参阅使用 Fetch 的 MDN 指南

fetch('http://example.com/movies.json')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(myJson);
  });

response.json()给你一个承诺。

您需要一个新then函数来从中获取价值。


推荐阅读