Currently trying to make a system that will change a button's color based on if the streamer on the button is live or not. I have a way to download the json string into a variable but I don't know what to do with that. I know I have to check if the variable "stream" in the json output is null which means the streamer is offline but I have 0 clue on how to do that.
I'll edit it with the code that I currently have. I got the json being properly parsed, doing r.stream gives me the appropriate data, but I can't figure out how to figure out if the stream is live or not. This is supposed to check on button press which will refresh the data.
private void Refresh_Click(object sender, RoutedEventArgs e)
{
string url = @"https://api.twitch.tv/kraken/streams/camoduck?client_id=xskte44y2wfqin464ayecyc09nikcj";
var json = new WebClient().DownloadString(url);
Rootobject r = JsonConvert.DeserializeObject<Rootobject>(json);
Console.WriteLine(r.stream);
if r.stream.game = "Grand Theft Auto V"
{
_1GUnit1.Background = Brushes.Red;
}
}
.......
var json = new WebClient().DownloadString(url);
var r = JsonConvert.DeserializeObject<Rootobject>(json);
Console.WriteLine(r.stream);
if (r.stream==null) //How a null check can be done
{
_1GUnit1.Background = Brushes.Red;
}
BTW: If you are using "http://json2csharp.com/", It is propably RootObject
not Rootobject