獲取數據我有一個JSON數據和代碼一個div。我想獲得連接從JSON文件數據到人更新容器股利。我嘗試了下面的代碼。但那不起作用。請幫我從JSON文件中獲取來自連接的數據。 JSON數據和人更新容器文件都在同一個HTML頁面。謝謝。如何從JSON文件
var feed_json = [{
\t \t
'teams' : [ {"total_count": '32'},
"count" : "10",
"url" : ""
},
{ "id" : "id2",
"name" : "Group 2",
"count" : "55",
"url" : ""
}
],
'connections': [ {'total_count' : '110'},
\t { "id" : "id1",
\t "name" : "Gossip Gang",
\t "count" : "20",
\t "url" : ""
\t },
\t { "id" : "id2",
\t "name" : "JEC Folks",
\t "count" : "90",
\t "url" : ""
\t }
\t ]
}];
var feedConnections = feed_json.connections;
\t \t for(var i = 0; i < feedConnections.length; i++) {
\t \t \t var connection = feedConnections[i];
\t \t \t var id = connection.id;
\t \t \t var name = connection.name;
\t \t \t var count = connection.count;
\t \t \t var connectionFeed = $('<div><div id = '+ id +' style = "margin-top: 10px;"> <span class="expandIcon1" style="float: right;"> <img width="28" height="28" src="/media/images/icons/arrow-Down-lines.png"/> </span> <span class="barTitle">'+ name + '<span> (' + count + ')</span></span></div></div>');
\t \t \t $('.people-update-container').append(connectionFeed);
\t \t }
<div class = "people-update-container" style = "display: none;">
</div>
刪除「[]」在你的JSON字符串 – Max
不知道我是注意到只有一個,但你必須在你的團隊屬性無效JSON數據。 – ThatAwesomeCoder
您的JSON無效。 –