0

私は最近、twitch json api を使用してみました。json の経験がなかったので、それは素晴らしい挑戦でしたが、json2csharp.com を使用して、json 文字列を次のようなクラスに変換しました。

class TwitchAPI
{
    public class Preview
    {
        public string small { get; set; }
        public string medium { get; set; }
        public string large { get; set; }
        public string template { get; set; }
    }

    public class Links
    {
        public string self { get; set; }
        public string follows { get; set; }
        public string commercial { get; set; }
        public string stream_key { get; set; }
        public string chat { get; set; }
        public string features { get; set; }
        public string subscriptions { get; set; }
        public string editors { get; set; }
        public string teams { get; set; }
        public string videos { get; set; }
    }

    public class Channel
    {
        public bool mature { get; set; }
        public string status { get; set; }
        public string broadcaster_language { get; set; }
        public string display_name { get; set; }
        public string game { get; set; }
        public string language { get; set; }
        public int _id { get; set; }
        public string name { get; set; }
        public string created_at { get; set; }
        public string updated_at { get; set; }
        public object delay { get; set; }
        public string logo { get; set; }
        public object banner { get; set; }
        public string video_banner { get; set; }
        public object background { get; set; }
        public string profile_banner { get; set; }
        public object profile_banner_background_color { get; set; }
        public bool partner { get; set; }
        public string url { get; set; }
        public int views { get; set; }
        public int followers { get; set; }
    }

    public class Stream
    {
        public long _id { get; set; }
        public string game { get; set; }
        public int viewers { get; set; }
        public string created_at { get; set; }
        public int video_height { get; set; }
        public int average_fps { get; set; }
        public int delay { get; set; }
        public bool is_playlist { get; set; }
    }
}

今、私はビューアにアクセスしようとしていますが、アクセスできません。私はこのようにします。

TwitchAPI twitchapi = new TwitchAPI();
string viewers = "" + twitchapi.Stream.viewers;
4

2 に答える 2

1

Stream内のクラスの名前です。見る限り、クラスTwitchAPI内でフィールドをまったく宣言していません。TwitchAPIしたがって、次を使用できます。

TwitchAPI.Stream stream = new TwitchAPI.Stream();
string viewers = stream.viewers.ToString();

TwitchAPI...しかし、現時点ではのインスタンスに関連付けられたストリームはありません。

(余談ですが、利用可能な Twitter API クライアントはたくさんあると思います。独自の Twitter API の構築に取り組むのではなく、Twitter で何かを行うことが目的である場合は、既存のものを使用することをお勧めします。)

于 2016-04-30T15:21:22.923 に答える