首页 > 解决方案 > 未捕获(承诺中)TypeError:无法读取未定义的属性“Modul1”

问题描述

我想从 JSON 中读取数据,但是出现了这个错误:

(index):93 Uncaught (in promise) TypeError: Cannot read property 'Modul1' of undefined:

<button class="accordion" Tag 2></button>

<div id = "tag2">

fetch('DB.json')
    .then(function(resp) {
        return resp.json();
    })
    .then(function(data) {
        console.log(data);
    })
    .then(data => {
        console.log(data)
        document.querySelector("#tag2").innerHTML = data.Modul1
    });

json文件:

{
  "Modul1": [{
    "Einheit1": [{
        "MentorVideo_1_1_0": "LINK",
        "Erledigt": true
      },
      {
        "HeldenVideo": "LINK",
        "Erledigt": true
      },
      {
        "Fragebogen_1_1_1": "LINK",
        "Erledigt": true
      },
      {
        "Deckblatt1_1_1": "LINK",
        "Erledigt": true
      }
    ]
  }

标签: json

解决方案


推荐阅读