【发布时间】:2021-09-05 06:33:00
【问题描述】:
我正在尝试从 OpenWeather API 获取数据。根据文档,响应是 JSON。但是我收到以下错误:
SyntaxError: Unexpected token < in JSON at position 0
useEffect(() => {
fetch(`api.openweathermap.org/data/2.5/weather?q=${CITY_NAME}&appid=${API_KEY}`)
.then(
(res)=> res.json()
.then((data)=>{
console.log(data)
})
.catch((error)=>{
console.log(error)
})
)
}, [])
当我查看开发人员工具时,我还有一个状态码 304:未修改。
很少有问题与我的问题相匹配,但没有一个可以解决我的问题,例如: Fetching JSON returns error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 和
React Js: Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0
【问题讨论】:
-
@yudhiesh 是的!有效