错误:无法将当前 JSON 对象(例如 { "name" : "value" })反序列化为类型"System.Collections.Generic.List"1



我正在尝试将API json响应反序列化为列表。BUt我得到错误:无法将当前JSON对象(例如{"name"value"}(反序列化为类型"System.Collections.Generic.List"1

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

var response = Newtonsoft.Json.JsonConvert.DeserializeObject<List<EndofDay.Insrtumentxxx>>(Content);

这是我的类,包含列表:

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响应是数组,并且您已声明为单个对象。您必须申报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; }   
}

相关内容

最新更新