RestSharp,将 IRestRequest 内容作为可用内容返回

RestSharp, returning IRestRequest content as something usable

在 RestSharp 部门(以及 C# 部门),这是一个有点菜鸟的问题,所以如果这让您感到不快,请不要生气。

我最近开始在我的 C# 应用程序中使用 RestSharp,我已经通过 IRestRequest return 获得了我想要的内容。

问题是return这个内容只能获取为char

这可能有点含糊,所以这是我的代码:

IRestRequest applicationReq = new RestRequest("somewhere/something", Method.GET);
IRestResponse applicationResp = client.Execute(applicationReq);

我想实际使用 returned 的 applicationResp.Content,但 return 这个结果似乎是 char

有什么方法可以将其转换为更有用的东西吗?比如,Dictionary?

到目前为止,我什至发现 'extract' 来自 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 调用的 return 类型是 Dictionary<TKey, TValue>,您可以使用接受所需 return 类型 T 的通用版本类型:

IRestRequest applicationReq = new RestRequest("somewhere/something", Method.GET);
IRestResponse applicationResp = client.Execute<Dictionary<string, string>>(applicationReq);

Dictionary<string, string> returnedData = applicationResp.Data;