这是 RestSharp 部门(以及 C# 部门)的一个菜鸟问题,所以如果这让您感到不快,请不要生气。
我最近开始在我的 C# 应用程序中使用 RestSharp,我已经让它通过 IRestRequest 返回我想要的内容。
问题是它返回的这个内容只能作为char
获取。
这可能有点含糊,所以这是我的代码:
IRestRequest applicationReq = new RestRequest("somewhere/something", Method.GET);
IRestResponse applicationResp = client.Execute(applicationReq);
我想实际使用返回的 applicationResp.Content
,但它似乎将此结果返回为 char
。
有什么方法可以将其转换为更有用的东西吗?例如,字典
?
到目前为止,我什至发现从 applicationResp.Content
中“提取”此数据的唯一方法是将其转储到列表中,如下所示:
List<char> ar = new List<char>();
ar = applicationResp.Content.ToList();
尽管给我的是 char
列表。
谁能给我推荐一种将内容放入 Dictionary
的巧妙方法?
最佳答案
Can anyone recommend me a neat way of putting the content into a Dictionary
如果您知道 REST 调用的返回类型是 Dictionary<TKey, TValue>
,您可以使用接受类型 T
的通用版本所需的返回类型:
IRestRequest applicationReq = new RestRequest("somewhere/something", Method.GET);
IRestResponse applicationResp = client.Execute<Dictionary<string, string>>(applicationReq);
Dictionary<string, string> returnedData = applicationResp.Data;
关于c# - RestSharp,将 IRestRequest 内容作为可用内容返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764573/