2013-01-15 50 views
1

任何想法爲什麼我得到序列化錯誤?我試着用其他網絡方法,它的工作。只是這個特別。RestSharp序列化錯誤

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原始)}

+0

json是錯誤中提到的JsonArray的一種類型,並且您試圖將其轉換爲Dictonary或對象,將反序列化更改爲接受Array而不是對象。 – Nikshep

回答

0

看起來訂單是保留字。我將它改爲SaleOrder,它的功能就像一個魅力。