gpt4 book ai didi

javascript - 将 Fetch 与 Google Places API 结合使用

转载 作者:行者123 更新时间:2023-11-30 14:10:46 25 4
gpt4 key购买 nike

您好,这可能是一个非常新手的错误,但是有人知道为什么这是未定义的 console.logging 吗?当我向浏览器提交 url 时,我得到有效的 json 响应。谢谢

      fetch('https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=[API KEY HERE]&location=49.246292,-123.116226&radius=500000')
.then((resp) => {
resp.json();
})
.then((data) => {
console.log(data);
})
.catch(err => console.error(err));

最佳答案

因为您决定将箭头函数体包裹在花括号中,所以您需要专门返回数据:

.then((resp) => {
return resp.json();
})

或者删除大括号:

.then(resp => resp.json())

关于javascript - 将 Fetch 与 Google Places API 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54505814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com