[英]Error: Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List`1
I'm trying to deserialize an API json response into a list.我正在尝试将 API json 响应反序列化为列表。 BUt I get teh error: Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Collections.Generic.List`1
但是我收到错误:无法将当前的 JSON object(例如 {"name":"value"})反序列化为类型 'System.ZA9FC91939A389C7C73E7A3F3CBF4111CDZ
Here is the code which I'm using to deserialize:这是我用来反序列化的代码:
var response = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EndofDay.Insrtumentxxx>>(Content);
Here is my class that contains the list:这是我的 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; }
}
}
} }
Here is my json api response:这是我的 json api 回复:
{\"instrumentxxx\":
[{\"id\":\"B1QH8P2\",
\"APrice\":5.83,
\"BPrice\":6.83,
\"CPrice\":7.83,}]}
What am I missing?我错过了什么?
Your JSON response is array and you have declared as single object.您的 JSON 响应是数组,并且您已声明为单个 object。 You must declare
instrumentxxx as List<Instrumentxxx>
您必须
instrumentxxx as List<Instrumentxxx>
Here is the working code 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; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.