简体   繁体   English

如何从json格式的promise对象中获取数据

[英]how to fetch data from promise object which is in json format

I'm trying to calculate distance from google api using fetch now i convert data into json which is in promise object and json fromat here is my code and also the screenshot of what I'm getting now 我正在尝试使用fetch现在计算与google api的距离,我将数据转换为Promise对象中的json,而fromat的json是我的代码,也是我现在得到的屏幕截图

i try so far but getting undefined error every time. 我尝试到目前为止,但每次都会得到未定义的错误。

fetch(proxyurl + re)
            .then(function(response) {

                console.log (response.json());
            });

i want to get data of source and destination time and distance 我想获取源和目标时间和距离的数据

here is the screenshot https://i.stack.imgur.com/Dz51R.png 这是截图https://i.stack.imgur.com/Dz51R.png

Try to update your fetch method like this: 尝试像这样更新您的提取方法:

fetch('https://api-endpoint.com')
    .then(response => response.json())
    .then(data => {
       console.log(data);
    });

Demo with github users endpoint: https://codesandbox.io/s/prod-bush-wqn70 带有github用户端点的演示: https : //codesandbox.io/s/prod-bush-wqn70

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM