无法在C#中反序列化JSON结果。 输入字符串格式错误不正确

我试图将json输出反序列化为C#对象。 JSON结果:

{"order":{"commission":3.490000,"cost":4.490000,"duration":"day","extended_hours ":false,"fees":0.000000,"class":"equity","price":1.000000,"quantity":1.000000,"r equest_date":"2013-11-26T09:43:17.118Z","result":true,"side":"buy","status":"ok" ,"symbol":"DIS","type":"limit"}} 

我从JSON派生的类:

  public class Rootobject { public Order Order { get; set; } } public class Order { public float commission { get; set; } public float cost { get; set; } public string duration { get; set; } public bool extended_hours { get; set; } public int fees { get; set; } public string _class { get; set; } public int price { get; set; } public int quantity { get; set; } public DateTime request_date { get; set; } public bool result { get; set; } public string side { get; set; } public string status { get; set; } public string symbol { get; set; } public string type { get; set; } } 

用于反序列化的代码(来自Newtonsoft的JSON.NET):

  Rootobject ord = JsonConvert.DeserializeObject(responsebody); 

我收到以下错误。

  Unhandled Exception: System.FormatException: Input string was not in a correct format. at Newtonsoft.Json.Utilities.ConvertUtils.Int32Parse(Char[] chars, Int32 start, Int32 length) at Newtonsoft.Json.JsonTextReader.ParseNumber() at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.JsonTextReader.ReadInternal() at Newtonsoft.Json.JsonReader.ReadAsInt32Internal() at Newtonsoft.Json.JsonTextReader.ReadAsInt32() at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(Jso nReader reader, JsonContract contract, Boolean hasConverter) 

我已经尝试将反序列化的结果保存到一个工作正常的“动态”对象。 但我不想使用动态对象来映射字段。

请指教。

注意:第三方API也会发送一个名为“class”的字段。 当我尝试直接调用该字段时,如何在编译时出错时调用此方法。

Order类中的fees属性定义为int但在JSon文本中它是0.00000 ,即floatdouble 。 我认为您可能需要将fees属性设置为float ,以便正确解析它。 pricequantity属性看起来也一样。