2016-05-31 4 views
1

私は、このAPIの呼び出しがあります。ここでは辞書オブジェクトのキーの値はどのようにして調べることができますか?

HttpResponse<string> response = 
    Unirest.get("https://wordsapiv1.p.mashape.com/words/" + word.Name) 
    .header("X-Mashape-Key", "xxxx") 
    .header("Accept", "application/json") 
    .asJson<string>(); 

HttpResponseのためのクラスです:

public class HttpResponse<T> 
{ 
    public HttpResponse(HttpResponseMessage response); 

    public T Body { get; set; } 
    public int Code { get; } 
    public Dictionary<string, string> Headers { get; } 
    public Stream Raw { get; } 
} 

私は問題ボディ(response.Body)を取得したり、コードが、私は何をしたい全くありませんこのヘッダを取得することです:

[7] = {[X-RateLimit-requests-Remaining, 2498]} 

誰かが私が返されたレスポンスをチェックして、01の値を見つけることができる方法を教えてもらえます?

+1

方法について: 'response.Headers [「X-レート制限-requests-Remaining "]'?だから、辞書がどのように機能するか知っていますか? – ckruczek

+0

この「Unirest」とは何ですか?また、そのメソッドが.NETの命名規則に従っていない理由は何ですか? –

+0

@MattiVirkkunenこれは[軽量HTTPリクエストライブラリ](http://unirest.io/net.html)です。この名前はおそらく他のサポートされている言語との互換性のためです。 –

答えて

4

辞書にはindexerと呼ばれるものがあります。インデクサーのデータ型は、KeyDictionary<Key,Value>)のデータ型です。

インデクサは、プロパティのゲッターとセッターと類似しており、このように実装されていますでしょうあなたの場合

public TValue this[TKey index] 
{ 
    // this will return when being called e.g. 'var x = dictionary[key];' 
    get { return whatever; } 

    // and here 'value' is whatever you pass to the setter e.g. 'dictionary[kex] = x;' 
    set { whatever = value; } 
} 

// "Key" is just an example, use "X-RateLimit-requests-Remaining" instead ;) 
response.Headers["Key"]; 
関連する問題