【发布时间】:2016-01-30 09:11:01
【问题描述】:
请帮助我。我在哪里缺少信息? 我需要反序列化以下 JSON 字符串。
{"results":[{"series":[{"name":"PWR_00000555","columns":["time","last"],"values":[["1970-01-01T00 :00:00Z",72]]}]}]}
为此,我定义了我的类:
public class Serie
{
public Serie()
{
this.Points = new List<object[]>();
}
[JsonProperty(PropertyName = "results")]
public string results { get; set; }
[JsonProperty(PropertyName = "series")]
public string sries { get; set; }
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "columns")]
public string[] ColumnNames { get; set; }
[JsonProperty(PropertyName = "values")]
public List<object[]> Points { get; set; }
但是当我尝试使用反序列化器时,它给出了一个异常。
{"无法将当前 JSON 对象(例如 {\"name\":\"value\"})反序列化为类型 'System.Collections.Generic.List`1[InfluxDB.Serie]',因为该类型需要要正确反序列化的 JSON 数组(例如 [1,2,3])。\r\n要修复此错误,请将 JSON 更改为 JSON 数组(例如 [1,2,3])或将反序列化类型更改为可以从 JSON 对象反序列化的普通 .NET 类型(例如,不是整数之类的原始类型,不是数组或 List
之类的集合类型)。也可以将 JsonObjectAttribute 添加到该类型以强制其反序列化一个 JSON 对象。\r\n路径“结果”,第 2 行,位置 12。"}
【问题讨论】:
标签: c# json serialization json.net