C# RestSharp-无法将System.String的对象强制转换为System.Generic.IDictionary类型
我是新来的。我有一个用python编写的Restful服务writein,它返回一条Json消息。我编写了一个C#client,使用RestSharp将json消息反序列化到对象 回应内容如下: “\”[{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ response.data为空 响应对象中的内部异常为 无法将“System.String”类型的对象强制转换为“System.Collections.Generic.IDictionary`2[System.String,System.object]”类型 以下是我的代码:C# RestSharp-无法将System.String的对象强制转换为System.Generic.IDictionary类型,c#,.net,http,rest,C#,.net,Http,Rest,我是新来的。我有一个用python编写的Restful服务writein,它返回一条Json消息。我编写了一个C#client,使用RestSharp将json消息反序列化到对象 回应内容如下: “\”[{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ response.data为空 响应对象中的内部异常为 无法将“Syste
public class QuartzServiceAdapter
{
const string BaseUrl = "http://localhost:7666/ahs/";
public QuartzServiceAdapter() { }
public T Execute<T>(RestRequest request) where T : new()
{
var client = new RestClient();
client.BaseUrl = BaseUrl;
var response = client.Execute<T>(request);
return response.Data;
}
public List<RootObject> GetBond()
{
var request = new RestRequest(Method.GET);
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
request.Resource = "getabond";
//request.RootElement = "RootObject";
return Execute<List<RootObject>>(request);
}
}
你知道为什么反序列化失败了吗?
提前谢谢你 您是否有返回的json示例?是否可以使用
.Execute()
而不是.Execute()
?在使用类型化调用时,我在核心数据类型(例如,double
)方面也遇到了类似的错误。在该代码路径中,库尝试将您的值分配给IDictionary
,而不管它是什么类型。
public class RootObject
{
public double coupon { get; set; }
public string cusip { get; set; }
public int currface { get; set; }
public int origface { get; set; }
}