【发布时间】:2019-05-12 01:18:58
【问题描述】:
我有一个看起来像这样的复杂 JSON:
{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "test-name",
"tags": {
"tag1": "0"
"tag2": "1"
},
"columns": [
"time",
"mean"
],
"values": [
[
"2018-12-03T10:18:37.3Z",
0
]
]
}
]
}
]
}
上面的POCO是这样的:
public class Tags
{
public string tag1 { get; set; }
public string tag2 { get; set; }
}
public class Series
{
public string name { get; set; }
public Tags tags { get; set; }
public List<string> columns { get; set; }
public List<List<object>> values { get; set; }
}
public class Result
{
public int statement_id { get; set; }
public List<Series> series { get; set; }
}
public class RootObject
{
public List<Result> results { get; set; }
}
问题是,Tags 类中的属性是动态的。可以只有一个标签,2 个或更多标签,仅在运行时确定。
我正在尝试使用 Newtonsoft.Json 将其解析为像 Dictionary<string, <Dictionary<string, object[]>>> 这样的嵌套字典,其中字典的键是标签的值,object[] 包含值列表(只是值,而不是时间戳)。
【问题讨论】:
-
您能摆脱
Tags类,而是将其添加为标签的属性吗?public IDictionary<string, JToken> Tags { get; set; }
标签: c# json asp.net-core-2.1 .net-core-2.1