How to fetch _links values?

Hi everyone,
I have a problem :

  • How to fetch _links value in C# ? To deserialize i use this code :

    WebClient strJson = new WebClient();
    string test = strJson.DownloadString(“https://api.twitch.tv/kraken/streams/ogaminglol”);
    DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Streams));
    MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(test));
    Streams stream = (Streams)js.ReadObject(ms);
    //label1.Text = "Title : " + stream.game;
    ms.Close();

My “Streams” class who receive the informations about streams :

[DataContract]
class Streams
{
    [DataMember]
    public string self { get; set; }

    [DataMember]
    public string channel { get; set; }

    [DataMember]
    public Stream stream { get; set; }
}

Self and channel is null because in https://api.twitch.tv/kraken/streams/ogaminglol they are in section “_links”. I hope u understand my problem.

Thx, Froelicher.

Nobody know ? Please help me :smiley:

I’m not quite familiar with C#'s built-in json but I’m pretty sure that’s how it works:

[DataContract]
class Streams
{
	[DataMember]
	public _Links _links { get; set; }

	[DataMember]
	public Stream stream { get; set; }

	[DataContract]
	public class _Links
	{
		[DataMember]
		public string self { get; set; }

		[DataMember]
		public string channel { get; set; }
	}

	[DataContract]
	public class Stream
	{
		...
	}
}

Thanks for your answer Freddy.
I can create Links class but i have many section “Links” so i need to create one class by links ?

Just do the same using the structure above: http://pastebin.com/8Zrjg3TR
As you can see, I renamed the inner Links class to ChannelLinks. That’s not necessary but I prefer it that way instead of having multiple classes with the same name.

Ok nice, thanks for your help ! I will tell you if your solution is the best.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.