簡體   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