Javascript 从JSON解析YouTube用户源

Javascript 从JSON解析YouTube用户源,javascript,jquery,json,youtube,Javascript,Jquery,Json,Youtube,我正在尝试制作一个脚本,以获取特定用户在YouTube上最近2次上传的JSON提要。我试着使用这个脚本 <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script> <script type="text/javascript"> // Set variables needed for query var

我正在尝试制作一个脚本,以获取特定用户在YouTube上最近2次上传的JSON提要。我试着使用这个脚本

<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'></script>
<script type="text/javascript">
// Set variables needed for query
var URL = "https://gdata.youtube.com/feeds/api/users/";
var UserName = "MyUsername";
var jsonFormat = "/uploads?v=2&alt=jsonc&max-results=2";
// Construct the JSON feed of the YouTube user's channel
var ajaxURL = URL + UserName + jsonFormat;
// Get the last videos of the YouTube account, parse it into HTML code
$.getJSON(ajaxURL, function(data){
     var htmlString = "";

    $.each(data.items, function(i,item){       
        // Here's where we piece together the HTML
        htmlString += '<iframe class="videos" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/';
        htmlString += item.id;
        htmlString += '?autoplay=0" frameborder="0"></iframe>';
    });

    // Pop our HTML in the #videos DIV
    $('#videos').html(htmlString);

});

//设置查询所需的变量
变量URL=”https://gdata.youtube.com/feeds/api/users/";
var UserName=“MyUsername”;
var jsonFormat=“/uploads?v=2&alt=jsonc&max results=2”;
//构建YouTube用户频道的JSON提要
var ajaxURL=URL+UserName+jsonFormat;
//获取YouTube帐户的最后视频,将其解析为HTML代码
$.getJSON(ajaxURL,函数(数据){
var htmlString=“”;
$.each(data.items,function(i,item){
//这里是我们拼凑HTML的地方
htmlString+='';
});
//在#videos DIV中弹出我们的HTML
$('#videos').html(htmlString);
});


我一直在使用类似的脚本解析flickr的JSON,它工作得很好。。YouTube的提要可能出了什么问题?

您已经将从YouTube返回的API放在javascript对象
数据中,但请记住,YouTube还将返回的对象封装在名为
数据的对象中

因此,在第14行中,当您开始遍历数据集时:

$.each(data.items, function(i,item){ 
。。。实际上应该是:

$.each(data.data.items, function(i,item){ 

下面是您的代码(已更正)放在JSFIDLE中:

非常感谢,这是一个很大的帮助