我的 JSON 如下所示:
{
"statistics": [
{
"total_questions": 4152031,
"views_per_day": 2198092.55,
"api_version": {
"version": "1.0",
"revision": "2012.10.30.200"
},
"site": {
"name": "Stack Overflow",
"logo_url": "http://cdn.sstatic.net/stackoverflow/img/logo.png",
"api_endpoint": "http://api.stackoverflow.com",
"site_url": "http://stackoverflow.com",
"description": "Q&A for professional and enthusiast programmers",
"icon_url": "http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png",
"aliases": [
"http://www.stackoverflow.com"
],
"state": "normal",
"styling": {
"link_color": "#0077CC",
"tag_foreground_color": "#3E6D8E",
"tag_background_color": "#E0EAF1"
}
}
}
]
}
Javascript是:
$.getJSON('json1', function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="'+ statistics.data.key +'"> ' + statistics.data.val +'</li>')
});
$('<ul />', {
'class':'ulLI',
'html':items.join('')
}).appendTo('body');
});
问题是我没有正确地访问统计数组中的数据,然后访问站点对象?你能告诉我如何访问这些对象/数组中的数据并将其附加到 html 中吗?