这通常意味着从服务器返回的数据不是 JSON 格式。您需要检查服务器返回的数据格式是否正确。如果您正在使用 fetch() 方法,那么可以在处理响应之前检查响应的 type 属性是否为 "json"。如果不是,那么您需要手动将响应转换为 JSON 格式。例如:
fetch(url) .then(response => { if (!response.ok) { throw new Error(response.statusText); } if (response.type !== 'json') { return response.text().then(text => JSON.parse(text)); } else { return response.json(); } }) .then(data => { console.log(data); }) .catch(error => { console.error(error); });