使用jQuery getJSON添加到JSON文件

时间:2013-01-06 15:52:20

标签: jquery json

目前我有一个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 },

0 个答案:

没有答案