读取JSON文件时出现语法错误

时间:2020-09-18 05:39:09

标签: javascript json file fetch-api

我正在尝试从保存在根文件夹中的json文件读取数据,这是我得到的错误:

未捕获(承诺)语法错误:JSON.parse:预期属性名称或JSON数据第2行第2列的'}'

代码是:

function getData(){
      fetch("./data.json")
      .then(response => {
          return response.json();
      })
      .then(data => {
          console.log(data);
      })
      .catch(error => {
          console.log(error);
      })
  }
  
 getData(); 

0 个答案:

没有答案