[英]RestSharp serialization error
Any idea why i am getting serialization error? 知道为什么我会出现序列化错误吗? I tried it with other web methods and it worked.
我尝试了其他网络方法,但效果很好。 Just this particular.
只是这个特殊。
public T Execute<T>(RestRequest request) where T : new()
{
var client = new RestClient
{BaseUrl = BaseUrl, Authenticator = new HttpBasicAuthenticator(AccountSid, SecretKey)};
var response = client.Execute<T>(request);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
return response.Data;
}
This is the object. 这是对象。
public class Order
{
public Order() { }
public string ProductName { get; set; }
public double SoldPrice { get; set; }
public double Fees { get; set; }
public String BuyerEmail { get; set; }
public String BuyerName { get; set; }
}
This is my JSON. 这是我的JSON。
"[{\"ProductName\":\"Demo Hinges\",\"SoldPrice\":700.0,\"Fees\":21.0,\"Size\":\"\",\"BuyerEmail\":\"\",\"BuyerName\":\"\"}]"
I am getting this error. 我收到此错误。
System.InvalidCastException: Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'. System.InvalidCastException:无法将类型为“ RestSharp.JsonArray”的对象转换为类型为“ System.Collections.Generic.IDictionary`2 [System.String,System.Object]”。 at RestSharp.Deserializers.JsonDeserializer.FindRoot(String content) at RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response) at RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)}
在RestSharp.Deserializers.JsonDeserializer.FindRoot(字符串内容)在RestSharp.Deserializers.JsonDeserializer.Deserialize [T](IRestResponse响应)在RestSharp.RestClient.Deserialize [T](IRestRequest请求,IRestResponse原始)}
Looks like Order is reserved word. 看起来订单是保留字。 I changed it to SaleOrder and it worked like a charm.
我将其更改为SaleOrder,它就像一个魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.