[英]RestSharp serialization error
知道為什么我會出現序列化錯誤嗎? 我嘗試了其他網絡方法,但效果很好。 只是這個特殊。
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;
}
這是對象。
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; }
}
這是我的JSON。
"[{\"ProductName\":\"Demo Hinges\",\"SoldPrice\":700.0,\"Fees\":21.0,\"Size\":\"\",\"BuyerEmail\":\"\",\"BuyerName\":\"\"}]"
我收到此錯誤。
System.InvalidCastException:無法將類型為“ RestSharp.JsonArray”的對象轉換為類型為“ System.Collections.Generic.IDictionary`2 [System.String,System.Object]”。 在RestSharp.Deserializers.JsonDeserializer.FindRoot(字符串內容)在RestSharp.Deserializers.JsonDeserializer.Deserialize [T](IRestResponse響應)在RestSharp.RestClient.Deserialize [T](IRestRequest請求,IRestResponse原始)}
看起來訂單是保留字。 我將其更改為SaleOrder,它就像一個魅力。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.