目前我有一个 HTML 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JSON Sample</title>
</head>
<body>
<div id="placeholder"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$.getJSON('data.json', { "firstName":"Matt", "lastName":"Jam", "joined": { "month":"July", "day":12, "year":2012 }, function(data) {
var output="<ul>";
for (var i in data.users) {
output+="<li>" + data.users[i].firstName + " " + data.users[i].lastName + "--" + data.users[i].joined.month+"</li>";
}
output+="</ul>";
document.getElementById("placeholder").innerHTML=output;
});
</script>
</body>
</html>
和一个 data.json 文件:
{"users":[
{
"firstName":"Ray",
"lastName":"Villalobos",
"joined": {
"month":"January",
"day":12,
"year":2012
}
},
{
"firstName":"John",
"lastName":"Jones",
"joined": {
"month":"April",
"day":28,
"year":2010
}
}
]}
我的问题是 - 我必须向 JSON 文件添加什么才能返回我通过 jquery getJSON 函数传递的信息?( "firstName":"Matt", "lastName":"Jam", "joined": { "month":"July", "day":12, "year":2012 },
)