我已经浏览了网页/文档,但无法找出为什么这不起作用。
我正在尝试从JSON文件中插入数据(引用):
{"quotesArray":[{
"personName": "Albert Einstein",
"quote": "Look deep into nature, and then you will understand everything better."
},
{
"personName": "Stephen Hawking",
"quote": "Look deep into nature, and then you will understand everything better."
},
{
"personName": "Confucius",
"quote": "Life is really simple, but we insist on making it complicated."
}]}
使用以下JS将其转换为简单的HTML div:
$(document).ready(function() {
$("#realquote").on("click", function() {
$.getJSON('/json/quotes.json', function(data) {
var html = " ";
data.forEach(function(val) {
var keys = Object.keys(val);
html += "<div class = 'text-output'>";
keys.forEach(function(key){
html += val[key];
});
html += "</div>"
});
$(".realquote").html(html);
});
});
});
但是每次我都会收到错误信息:“TypeError: data.forEach不是一个函数”,我无法弄清原因。
如果有人能指导我正确的方向,将不胜感激!