我的 JSON 看起来像这样:
{
"content": [
{
"title": "'I need some rest'",
"description": "Descript One",
"link": "http://www.google.com/?id=90#hhjjhjC-RSS",
"guid": "http://www.google.com/?id=90",
"pubDate": "Fri, 15 Oct 2002 08:27:27 GMT"
},
{
"title": "I have no objection",
"description": "descroption will ne populated here",
"link": "http://www.google.com/?id=90#hhjjhjC-RSSRSS",
"guid": "http://www.google.com/?id=9werwer0",
"pubDate": "Fri, 14 Aug 2009 15:54:26 GMT"
},
{
"title": "Mised the Buss",
"description": "Missed the bus decsription",
"link": "http://www.google.com/?CMP=OTC-RSS",
"guid": "http://www.google.com/",
"pubDate": "Fri, 21 Jul 2009 15:08:26 GMT"
}
]
}
有人可以指导告诉我如何遍历此 JSON 并将其附加到 html。我正在尝试这样的事情?
$(function() {
$.getJSON("http://crossdomain.com/path/to/abovejsonfile", function(data) {
$.each(data.item[0], function(index, it){
var d = $('<div>'+ it.title +'</div>');
alert(d); //doesn't work
});
});
我渲染的页面应该是这样的?
<div class="container">
<div class="node" id="n1">
<div class="title">Title should come here</div>
<a class="link">Link</a>
<div class='d'>Date should be here</div>
</div>
<div class="node" id="n2">
<div class="title">Title should come here</div>
<a class="link">Link</a>
<div class='d'>Date should be here</div>
</div>
<div class="node" id="n3">
<div class="title">Title should come here</div>
<a class="link">Link</a>
<div class='d'>Date should be here</div>
</div>
......
</div>
任何帮助都深表感谢。
麦克风