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

标签 c# restsharp

这是 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/

相关文章:

c# - 为什么我不能使用 C# 将数据插入本地数据库(SQL 精简版)?

c# - 如何在 RestSharp 中反序列化 JSON?

c# - Restsharp - 尝试序列化根节点上的 xmlns 属性时出错

c# - 我想知道在迭代数据读取器对象时连接状态和 'yield' 对代码性能的影响

c# - LINQ lambda 表达式中的 "error CS0103: the name ' w ' does not exist in the current context"

c# - 使用 Json.NET 反序列化 : Requiring a property/key to be present

c# - RestClient - 请求返回 500 内部服务器错误(内容为 html)并且没有 ErrorMessage

windows-phone-7 - WP7 - 防止 RestSharp 缓存

c# - 使用 Mailgun API 和 RestSharp C# 发送 HTML 电子邮件,导致消息在包含&符号 "&"时被截断

c# - Slider.Value 在不应该调整最小值时发生变化