javascript - 获取 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]]']?感谢您的回复
解决方案
fetch('http://example.com/movies.json') .then(function(response) { return response.json(); }) .then(function(myJson) { console.log(myJson); });
response.json()
给你一个承诺。
您需要一个新then
函数来从中获取价值。
推荐阅读
- c++ - 为什么我需要移动`std::unique_ptr`
- c# - 如果字符串的偶数位置包含元音,则使用 C# 从字符串中删除字符
- angular - 有什么方法可以将 youtube 嵌入 URL 转换为 Blob 对象
- amember - 您如何知道该产品是否曾在 AMEMBER 购买过?
- php - 如何从命令行或 c++ 运行 php-cgi 或等效项来模拟 MacOS 10.15 上的 Web 服务器?
- c# - 无法使用 C# 解析 SOAP 响应
- autodesk-forge - Autodesk Forge - Revit 坐标
- html - 如何使用角度将html输入类型日期占位符值更改为当前日期即时消息
- arrays - 2018 年 10 月 30 日 00:00:00 在 mongo 中将字符串更改为 iso 日期
- java - java.lang.ExceptionInInitializerError 与 TestNG + Cucumber + Maven