1

知道为什么我会收到序列化错误吗?我用其他网络方法尝试过,它奏效了。就是这个特别的。

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(String content) 在 RestSharp.Deserializers.JsonDeserializer.Deserialize[T](IRestResponse response) 在 RestSharp.RestClient.Deserialize[T](IRestRequest request, IRestResponse raw)}

4

1 回答 1

0

看起来 Order 是保留字。我将其更改为 SaleOrder,它就像一个魅力。

于 2013-01-15T18:29:51.013 回答