Error: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1
Error: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1
我正在尝试将 API json 响应反序列化到列表中。
但是我得到了错误:无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1
这是我用来反序列化的代码:
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EndofDay.Insrtumentxxx>>(Content);
这是我的 class 列表:
public class EndofDay
{
public Instrumentxxx instrumentxxx { get; set; }
public class Instrumentxxx
{
public string id { get; set; }
public double APrice { get; set; }
public double BPrice { get; set; }
public double CPrice { get; set; }
}
}
}
这是我的 json api 回复:
{\"instrumentxxx\":
[{\"id\":\"B1QH8P2\",
\"APrice\":5.83,
\"BPrice\":6.83,
\"CPrice\":7.83,}]}
我错过了什么?
您的 JSON 响应是数组,并且您已声明为单个对象。您必须声明 instrumentxxx as List<Instrumentxxx>
这是工作代码Click here
public class EndofDay
{
public List<Instrumentxxx> instrumentxxx { get; set; }
}
public class Instrumentxxx
{
public string id { get; set; }
public double APrice { get; set; }
public double BPrice { get; set; }
public double CPrice { get; set; }
}
我正在尝试将 API json 响应反序列化到列表中。 但是我得到了错误:无法将当前 JSON 对象(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1
这是我用来反序列化的代码:
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EndofDay.Insrtumentxxx>>(Content);
这是我的 class 列表:
public class EndofDay
{
public Instrumentxxx instrumentxxx { get; set; }
public class Instrumentxxx
{
public string id { get; set; }
public double APrice { get; set; }
public double BPrice { get; set; }
public double CPrice { get; set; }
}
}
}
这是我的 json api 回复:
{\"instrumentxxx\":
[{\"id\":\"B1QH8P2\",
\"APrice\":5.83,
\"BPrice\":6.83,
\"CPrice\":7.83,}]}
我错过了什么?
您的 JSON 响应是数组,并且您已声明为单个对象。您必须声明 instrumentxxx as List<Instrumentxxx>
这是工作代码Click here
public class EndofDay
{
public List<Instrumentxxx> instrumentxxx { get; set; }
}
public class Instrumentxxx
{
public string id { get; set; }
public double APrice { get; set; }
public double BPrice { get; set; }
public double CPrice { get; set; }
}