I'm trying to deserialize an API json response into a list. BUt I get teh error: Cannot deserialize the current JSON object (eg {"name":"value"}) into type 'System.Collections.Generic.List`1
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:
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:
{\"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. You must declare 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; }
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.