繁体   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

我正在尝试将 API json 响应反序列化为列表。 但是我收到错误:无法将当前的 JSON object(例如 {"name":"value"})反序列化为类型 'System.ZA9FC91939A389C7C73E7A3F3CBF4111CDZ

这是我用来反序列化的代码:

 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 响应是数组,并且您已声明为单个 object。 您必须instrumentxxx as List<Instrumentxxx>

这是工作代码点击这里

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM