1

我有 4 个 JSON 格式的玩家列表,并且 $.getJSON javascript 工作得很好,然后在我添加了 16 个 JSON 格式的玩家之后,表格中的玩家列表消失了。我做错了什么?

Javascript

$(document).ready(function() {
    $.getJSON("js/dataPokerPlayers.json", function(data) {
        $.each(data, function(i, data){
            $(".tableData tbody").append("<tr><td class=\"centertext\">" + data.rank + "</td><td>" + data.name + "</td><td class=\"centertext\">" + data.earnings + "</td><td class=\"centertext\">" + data.points + "</td><td class=\"centertext\">" + data.totalearnings + "</td></tr>");
        });
    });
});

JSON - http://www.elitedeafpoker.com/dev/js/dataPokerPlayers.json

我试图在 JSON 中删除所有 16 名球员,并让 4 名球员留在原来的位置,他们在桌面上表现得很好 - 发生了什么事?我只是为玩家的新数据复制/粘贴了 JSON 行。

4

3 回答 3

3

您的 JSON 缺少一些逗号,即在第四行之后。

[ 
    {"rank": "1", "name": "Chad Demon", "earnings": "$9,600", "points": "345", "totalearnings": "$72,500"},
    {"rank": "2", "name": "Clay Chaman", "earnings": "$8,600", "points": "245", "totalearnings": "$42,500"},
    {"rank": "3", "name": "Christian Luneborg", "earnings": "$7,800", "points": "145", "totalearnings": "$52,500"},
    {"rank": "4", "name": "Steve Drills", "earnings": "$6,500", "points": "45", "totalearnings": "$2,250"},
    {"rank": "5", "name": "Paul Sims",  "earnings": "$5,600", "points": "345", "totalearnings": "$11,500"},
    {"rank": "6", "name": "Melissa Suzy", "earnings": "$4,600", "points": "245", "totalearnings": "$24,500"},
    {"rank": "7", "name": "Philiip Samon", "earnings": "$3,800", "points": "145", "totalearnings": "$2,500"},
    {"rank": "8", "name": "Steve Glass", "earnings": "$2,500", "points": "45", "totalearnings": "$2,000"},
    {"rank": "9", "name": "Sven Zebers",    "earnings": "$1,600", "points": "345", "totalearnings": "$12,500"},
    {"rank": "10", "name": "Chris Spabling", "earnings": "$1,000", "points": "245", "totalearnings": "$22,500"},
    {"rank": "11", "name": "John Cozz", "earnings": "$500", "points": "145", "totalearnings": "$52,500"},
    {"rank": "12", "name": "Karlan Suller", "earnings": "$485", "points": "45", "totalearnings": "$2,500"},
    {"rank": "13", "name": "Kim Uzi",   "earnings": "$350", "points": "345", "totalearnings": "$12,500"},
    {"rank": "14", "name": "Eric Borg", "earnings": "$325", "points": "245", "totalearnings": "$21,500"},
    {"rank": "15", "name": "Jasper Russo", "earnings": "$250", "points": "145", "totalearnings": "$52,500"},
    {"rank": "16", "name": "Bruce Willis", "earnings": "$225", "points": "45", "totalearnings": "$42,500"},
    {"rank": "17", "name": "Tim Burdlen",   "earnings": "$200", "points": "345", "totalearnings": "$82,500"},
    {"rank": "18", "name": "Matt Erickson", "earnings": "$175", "points": "245", "totalearnings": "$22,500"},
    {"rank": "19", "name": "Matt Sears", "earnings": "$125", "points": "145", "totalearnings": "$62,500"},
    {"rank": "20", "name": "Dong Smith", "earnings": "$100", "points": "45", "totalearnings": "$32,500"}
]
于 2013-04-18T20:25:41.403 回答
1

解析 JSON 文档时出错。文档可能格式不正确。

看起来你缺少逗号。

尝试使用此工具来验证您的 JSON 文件。

于 2013-04-18T20:25:21.207 回答
1

如果您访问http://www.jsonlint.com并输入您的 JSON,您会看到主数组的项目之间缺少几个逗号。

于 2013-04-18T20:25:21.920 回答