我试图做的显示标题,链接,图像和视频的创作者的视频列表:S获取YouTube的数据,并将其写入作为列表项
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('http://gdata.youtube.com/feeds/users/Username/uploads?alt=json-in-script&callback=?&max-results=12&start-index=1', function(data) {
$.each(data.feed.entry, function(i, item) {
var title = item['title']['$t'];
var video = item['id']['$t'];
video = video.replace('http://gdata.youtube.com/feeds/videos/','http://www.youtube.com/v/');
videoID = video.replace('http://www.youtube.com/watch?v=','');
$('.allvideos').append('<a rel="shadowbox[video];height=390;width=640;" href="'+video+'" style="width:100%;display:block;"> '+title+'</a>');
Shadowbox.setup();
});
});
});
</script>
我怎样才能做这样的事情?
<div class="allvideos">
<div class="video">
<img src="[VIDEO_ICON]" />
<a href="[VIDEO_URL]">
<span>{NAME_VIDEO}</span>
<span>{NAME_CREATOR}</span>
</a>
</div>
</div>
谢谢。
你不应该手动构建链接,而是用`rel = alternate`和`type = text/html`查找'feed.entry.item.link`,并使用它的`href`属性。 @ Lachian-McDonald的回答是正确的。这个JSON的本地格式实际上是一个原子提要,所以这就是为什么它看起来很丑。如果您可以管理它,使用这些提要在atom + xpath中比使用json更容易。 – 2011-12-19 02:02:01