当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - List of Poker Players in table disappeared using JSON

问题描述:

I had 4 list of players in JSON and the $.getJSON javascript worked just fine and then after I added 16 more players in JSON then the list of players in the table disappeared. What did I do wrong?

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

I tried to remove all 16 players in JSON and leave 4 where they were before and they showed just fine on table - whats going on?? I simply copy/pasted the line of JSON for new data of players.

网友答案:

Your JSON is missing some commas, namely, right after the forth line of ever row.

[ 
    {"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"}
]
网友答案:

There was an error parsing the JSON document. The document may not be well-formed.

Looks like you are missing commas.

Try using this tool to validate your JSON file.

网友答案:

If you go to http://www.jsonlint.com and put your JSON in, you'll see there are several missing commas in between the main array's items.

分享给朋友:
您可能感兴趣的文章:
随机阅读: