Reputation: 2033
I understand that this is a typical error, but I cannoty figure out, where is the problem located? The link in browser opens normally with JSON structure, but in weatherRequest.json()
i even got an error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
.
Help, please...
let fetchWeather = async () => {
const weatherRequest = await fetch(`api.openweathermap.org/data/2.5/forecast?q=München,DE&appid=my_key`);
const weatherStore = await weatherRequest.json();
console.log('weatherStore', weatherStore);
}
fetchWeather();
Upvotes: 2
Views: 865
Reputation: 6916
This happened to me. Two fixes helped me resolve this issue.
axios
instead of fetch
. (Not sure why fetch didn't help)Install -> npm install axios
Use -> import axios from 'axios';
https://
like this https://api.openweathermap.org...
Upvotes: 1