简体   繁体   English

错误:无法将当前 JSON object(例如 {“name”:“value”})反序列化为类型 'System.Collections.Generic.List`1

[英]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.

相关问题 无法将当前 JSON object(例如 {"name":"value"})反序列化为类型 'System.Collections.Generic.List`1 - Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1 无法反序列化当前JSON对象(例如{“ name”:“ value”})为类型&#39;System.Collections.Generic.List - Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List 无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型&#39;System.Collections.Generic.List`1&#39; - Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List`1' JSON.Net - 无法将当前json对象(例如{“name”:“value”})反序列化为类型&#39;system.collections.generic.list`1 - JSON.Net - cannot deserialize the current json object (e.g. {“name”:“value”}) into type 'system.collections.generic.list`1 JsonSerializationException:无法将当前 JSON object(例如 {"name":"value"})反序列化为类型 'System.Collections。 - JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List JSON .NET-将当前JSON对象(例如{“ name”:“ value”})反序列化为类型&#39;System.Collections.Generic.List`1 - JSON .NET - annot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List`1 无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型“ System.Collections.Generic.ICollection`1 [System.Double]” - Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.ICollection`1[System.Double]' 无法将当前 JSON 对象(例如 {&quot;name&quot;:&quot;value&quot;})反序列化为类型 &#39;System.Collections.Generic.IList 问题 - Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IList problem 无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型“ System.Collections.Generic.IEnumerable`1 [WebApplication1.UserInfo]” - Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.IEnumerable`1[WebApplication1.UserInfo]' 无法将JSON对象反序列化为“System.Collections.Generic.List”类型 - Cannot deserialize JSON object into type 'System.Collections.Generic.List'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM