[英]How can I find out the value of the keys in a dictionary object?
我有这个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; }
}
我没有问题可以获取Body( response.Body
)或代码,但是我想做的就是获取此标头:
[7] = {[X-RateLimit-requests-Remaining, 2498]}
有人可以告诉我如何检查返回的响应并找出X-RateLimit-requests-Remaining
吗?
词典中有一个叫做索引器的东西。 索引器的数据类型是Key
的数据类型( Dictionary<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"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.