简体   繁体   English

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

[英]RestSharp, returning IRestRequest content as something usable

This is a bit of a noobie question in the RestSharp department (and the C# department for that matter), so if that rubs you the wrong way, please take no offence. 这是RestSharp部门(以及C#部门)的一个noobie问题,所以如果你用错误的方式摩擦你,请不要冒犯。

I've recently started using RestSharp in my C# application, and I've gotten it to return the content I'd like through an IRestRequest. 我最近开始在我的C#应用​​程序中使用RestSharp,我已经通过IRestRequest返回我想要的内容。

The problem is that it returns this content can only be obtained as char . 问题是它返回的内容只能作为char获得。

That might be a little vague, so here's my code: 这可能有点模糊,所以这是我的代码:

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

I want to actually use the applicationResp.Content that is returned, but it seems to return this result as char . 我想实际使用返回的applicationResp.Content ,但似乎将此结果作为char返回。

Is there any way I can convert this to something more usable? 有什么办法可以把它转换成更实用的东西吗? Like, for example a Dictionary ? 比如,例如一个Dictionary

Thus far, the only way I've even found to 'extract' this data from the applicationResp.Content is by dumping it to a list, as follows: 到目前为止,我甚至发现从applicationResp.Content “提取”这些数据的唯一方法是将其转储到列表中,如下所示:

List<char> ar = new List<char>();
ar = applicationResp.Content.ToList();

All that gives me though is along list of char s. 所有这一切都给了我一个char列表。

Can anyone recommend me a neat way of putting the content into a Dictionary ? 任何人都可以向我推荐一种将内容放入Dictionary的简洁方法吗?

Can anyone recommend me a neat way of putting the content into a Dictionary 任何人都可以向我推荐一种将内容放入词典的简洁方法

If you know the return type of your REST call is a Dictionary<TKey, TValue> , you can use the generic version which accepts a type T of the desired return type: 如果您知道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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM