[英]JSON - Cannot read property 'viewers' of undefined
I am trying to get a list of viewers from twitch and it keeps giving me an error even though I am pretty sure I have the right format ... 我正在尝试从抽搐中获取观众列表,即使我非常确定自己的格式正确,也一直给我一个错误...
here is the code and here is an example on jsfiddle: 这是代码, 这是jsfiddle的示例:
$(document).ready(function () {
$.getJSON("http://tmi.twitch.tv/group/user/nightblue3/chatters?callback=?", function (data) {
console.log(data.chatters.viewers); //This should be in the right format based of the json data?!
});
});
You named the variable data
, but that data
object has another data
object inside that contains the chatters.viewers
, so it should be : 您将变量命名为
data
,但是该data
对象内部还有另一个data
对象,其中包含chatters.viewers
,因此应为:
$.getJSON("http://tmi.twitch.tv/group/user/nightblue3/chatters?callback=?", function (data) {
console.log(data.data.chatters.viewers); //This should be in the right format based of the json data?!
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.