私の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>
どんな助けでも大歓迎です。
マイク