gpt4 book ai didi

javascript - Javascript JSON YouTube API viewCount不起作用

转载 作者:行者123 更新时间:2023-12-03 06:32:45 24 4
gpt4 key购买 nike

我需要使用JavaScript(Chrome扩展程序)获取视频的 View ,但无法正常工作。

码:

$(function() {
$.getJSON('http://gdata.youtube.com/feeds/api/videos/H542nLTTbu0?alt=json',function(data) {
$.each(data.feed.entry, function(i, item) {
var numViews = item['yt$statistics']['viewCount'];
});
});
});

但是,如果我尝试获取它们,则会显示错误消息:
Uncaught TypeError: Cannot read property 'entry' of undefined

最佳答案

您正在下载的JSON文件中没有“提要”属性-我建议使用某种工具(例如http://jsonviewer.stack.hu/)来调查JSON结构,并根据所需的属性来编辑代码。

编辑:看起来您需要的值存储在data.entry.yt$statistics.viewCount中。不需要each ...

编辑2:

$(function() {
$.getJSON('http://gdata.youtube.com/feeds/api/videos/H542nLTTbu0?alt=json',function(data) {
var numViews = +data.entry.yt$statistics.viewCount;
// + converts the string to int
});
});

关于javascript - Javascript JSON YouTube API viewCount不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18575015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com