Search code examples
c#jsonapitwitch

Twitch API get viewer count


I want to use the link http://tmi.twitch.tv/group/user/dreamhackcs/chatters for fetching the information about the channel. As you can see, it gives back a JSON response, but I only want the "chatter_count" number.

How can I go about fetching only that data from the web-response? I have never used an API for fetching data before. I just need to get the chatter_count to be a int or string value.


Solution

  • Parse the string to a JObject using Json.Net.

    You can do this with: JObject jObject = JObject.Parse(yourJsonString)

    Then use: int chatters = (int)jObject["chatter_count"]

    that should get your lucky number