data.json() is not a function (React)
问题 I have the following code: getWeather = e => { e.preventDefault(); const api_call = fetch( `http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=${API_KEY}` ); const data = api_call.json(); console.log(data); }; But I keep getting .json() is not a function. Not sure why I am getting that. 回答1: That's because you didn't wait for the request to end. Try this instead: const api_call = fetch( `http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=${API_KEY}` ).then(res =>