JSON格式问题? [英] JSON formatting issue?
问题描述
我正在尝试填充JSON数据的html表。我被提供了JSON数据,无法确定为什么它没有填充,但怀疑JSON可能没有正确格式化。当我使用其他样本数据时,它工作,然后当我提供JSON时,我提供它不起作用。我已经尝试将JSON复制到我的直接服务器上的文件中,链接到我提供的内容(这里:) [ ^ ]并将其插入myjson.com并重新格式化JSON数据。
这是我的代码:
I am trying to populate an html table of JSON data. I was provided the JSON data and cannot determine why it isn't populating but suspect the JSON may not be formatted properly. When I use other sample data it works, then when I sub in the JSON I was provided it doesn't work. I've tried copying the JSON into a file on my direct server, linking to what I was provided (here: ) [^] and inserting it on myjson.com and reformatting the JSON data.
Here is my code:
<script>
$(function() {
var entries = [];
var dmJSON = "https://api.myjson.com/bins/6sjud?callback=?";
$.getJSON( dmJSON, function(data) {
$.each(data.entries, function(i, f) {
var tblRow = "<tr>" + "<td>" + f.rank + "</td>" + "<td>" + f.name + "</td>" + "<td>" + f.march_rank + "</td>" + "<td> " + f.april_rank + "</td>" + "<td>" + f.may_rank + "</td>" + f.personal_volume + "</td>" + f.team_volume + "</td>" + "</tr>"
$(tblRow).appendTo("#incentive tbody");
});
});
});
</script>
<div class="wrapper">
<div class="profile">
<table id= "incentive" border="1">
<thead>
<th>Rank</th>
<th>Name</th>
<th>March</th>
<th>April</th>
<th>May</th>
<th>Highest Rank</th>
<th>Personal Volume</th>
<th>Team Volume</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
我可能出错的任何想法?
我尝试过:
我尝试重新格式化JSON并将其放入我自己服务器上的新文件中无效。
Any ideas where I could be going wrong?
What I have tried:
I have tried reformatting the JSON and putting it into a new file on my own server to no avail.
推荐答案
( function (){
var entries = [];
var dmJSON = https:// api.myjson.com/bins/6sjud?callback =?;
(function() { var entries = []; var dmJSON = "https://api.myjson.com/bins/6sjud?callback=?";
.getJSON(dmJSON, function (数据){
.getJSON( dmJSON, function(data) {
.each(data.entries, function (i,f){
var tblRow = < tr> + < span class =code-string> < td> + f.rank + < / td> + < ; td> + f.name + < / td> + < span class =code-string> < td> + f.march_rank + < / td> + < td> + f.april_rank + < / td> + < td> + f.may_rank + < / td> + f.personal_volume + < / td> + f.team_volume + < / td> + < / tr>
.each(data.entries, function(i, f) { var tblRow = "<tr>" + "<td>" + f.rank + "</td>" + "<td>" + f.name + "</td>" + "<td>" + f.march_rank + "</td>" + "<td> " + f.april_rank + "</td>" + "<td>" + f.may_rank + "</td>" + f.personal_volume + "</td>" + f.team_volume + "</td>" + "</tr>"
这篇关于JSON格式问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!