语法错误:app.js 中位置 0 处的 JSON 中出现意外标记 C [重复]

问题描述 投票:0回答:1

代码如下: 我收到一条错误消息:SyntaxError: Unexpected token C in JSON atposition 0 但这种情况有时会发生。

function fetchData(user_country) {
  fetch(`https://covid19-monitor-pro.p.rapidapi.com/coronavirus/cases_by_days_by_country.php?country=${user_country}`, {
      "method": "GET",
      "headers": {
        "x-rapidapi-key": "0eb507ba94mshbdcee33e20f63e2p1f00eajsn1967cf2bd741",
        "x-rapidapi-host": "covid19-monitor-pro.p.rapidapi.com"
      }
    })
    .then(response => {
      return response.json();
    })
javascript html fetch-api
1个回答
1
投票

您的 API 返回的响应不是可解析的 JSON 格式。首先,console.log

response
看看你得到了什么

然后你可以将其转换为JSON

© www.soinside.com 2019 - 2024. All rights reserved.