javascript - 如何从 json 格式的 promise 对象中获取数据
问题描述
我正在尝试使用 fetch 计算与 google api 的距离,现在我将数据转换为 promise 对象中的 json,json fromat 是我的代码,也是我现在得到的截图
我尝试到目前为止,但每次都得到未定义的错误。
fetch(proxyurl + re)
.then(function(response) {
console.log (response.json());
});
我想获取源和目的地时间和距离的数据
解决方案
尝试像这样更新您的 fetch 方法:
fetch('https://api-endpoint.com')
.then(response => response.json())
.then(data => {
console.log(data);
});
带有 github 用户端点的演示:https ://codesandbox.io/s/prod-bush-wqn70
推荐阅读
- authentication - 使用 Azure 应用服务身份验证的 HttpContext 用户为空
- c# - 使用 Microsoft.CodeAnalysis/Roslyn 获取 XML 文档
- javascript - 如何使用 XPath 解析 JavaScript 内容
- mongodb - $查找对象数组中的id
- c# - 如何在 C# 6.0 的泛型类中包含特定于类型的代码?
- python - 使用 python 对数据框进行多处理 SQL 查询
- python-3.x - 来自不同格式数据帧的新数据帧
- python - 如何将用户给出的输入与python中的整数或字符串进行比较
- node.js - docker 内的节点进程内存有限 - 可用方式低于
- reactjs - 类型 '(props: RouteProps) => JSX.Element' 不可分配给类型 'PropsWithChildren
'