json - 未捕获(承诺中)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
}
]
}
解决方案
推荐阅读
- c# - ConcurrentDictionary 线程安全有效地更改字典值内的属性
- pug - 如何在 Pug 模板中呈现此条件
- python - 修改文本文件中任意行的特定索引
- excel - VBA代码在运行时锁定Excel,但在单步执行代码时运行正常
- reactjs - 在 useState 中保存反应元素以获得良好的性能是一种很好的模式吗?
- sql - 有没有办法通过 SQLAlchemy 和 MariaDB 获得类似 NULLS LAST 的功能?
- python - 如何拆分数据框的行,将“\ n”视为分隔符
- javascript - 如果 HTML 输入元素的值没有被 RxJS 更改,如何停止管道?
- swift - Swift 5 中的并发竞争条件函数
- java - 如何修复通用循环数组队列中的 NullPointerException