0

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:

$(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?!
    });


});
user3195250
  • 127
  • 2
  • 13
  • try `data.data.chatters.viewers`. By the way.. I only get _Cannot read property 'viewers' of undefined_ – putvande Jun 28 '14 at 14:48
  • This error message means that `data.chatters` is undefined and therefore you cannot access the property `viewers`. So basically, your `data` object is not what you expect it to be. So what you can do is `console.log(data);` to see what `data` really is and what properties it actually has. – basilikum Jun 28 '14 at 14:54

1 Answers1

1

You named the variable data, but that data object has another data object inside that contains the chatters.viewers, so it should be :

$.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?!
});

Fiddle

putvande
  • 15,068
  • 3
  • 34
  • 50
  • Thankyou! That worked, and yeah I do get Cannot read property 'viewers' of undefined but I put 'x' cause was trying it with multiple things :) – user3195250 Jun 28 '14 at 14:53