fetch(`api.openweathermap.org/data/2.5/weather?q=${query}&appid={b4a02f3420e98aa54f5a688d40ce527b}`)
.then(response => response.json())
.then(result => {
setWeather(result);
setQuery('');
console.log(result);
})
其显示错误at 3131:1未指明(承诺) SyntaxError:在JSON中位于0
位置的意外令牌<
发布于 2021-05-21 13:18:30
有几件事需要改变:
{API key}
显示为占位符,实际的url不应该包含在键{}
--您正在从fetch
开始的url应该从https://
开始,否则它将尝试相对于当前原点获取。
const query = 'Brooklyn'
fetch(`https://api.openweathermap.org/data/2.5/weather?q=${query}&appid=b4a02f3420e98aa54f5a688d40ce527b`)
.then(response => response.json())
.then(result => console.log(result))
.catch(e => console.error(e))
发布于 2021-05-21 12:31:25
我想你把$
忘在appid=
之后了
fetch(`api.openweathermap.org/data/2.5/weather?q=${query}&appid=${b4a02f3420e98aa54f5a688d40ce527b}`)
发布于 2021-05-21 12:37:45
您是否已从邮递员处确认网址是否正在返回任何数据?也许API键是不正确的,并且没有数据返回。
https://stackoverflow.com/questions/67636867
复制相似问题