我正在尝试学习一些jQuery和javascript,并有一个整洁的项目来尝试。它涉及从JSON文件中提取数据并根据日期以表格形式显示它。我发现Dynatable看起来像我想做的那样,但我不断得到JSON输入的意外结束"错误。我使用与Dynatabe页面上给出的示例相同的语法,但它不返回任何记录。任何帮助将不胜感激,因为我确定我错过了一些简单的东西。 JSON文件名为json-records.json
[
{
"band": "Weezer",
"song": "GA Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
},
]

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="./jspkg-archive/jquery.dynatable.js"></script>
<script src="json-records.json"></script>
<style src="./jspkg-archive/jquery.dynatable.css"></style>
</head>
<body>
<table id="my-final-table">
<thead>
<th>Band</th>
<th>Song</th>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
$(document).ready( function(){
$('#my-final-table').dynatable();
});
var $records = $('#json-records'),
myRecords = JSON.parse($records.text());
$('#my-final-table').dynatable({
dataset: {
records: myRecords
}
});
</script>
</body>
</html>
&#13;
答案 0 :(得分:1)
你有一个流浪的&#39;,&#39;在您的JSON文件中
[
{
"band": "Weezer",
"song": "GA Scorcho"
},
{
"band": "Chevelle",
"song": "Family System"
}, <--- Here
]