【发布时间】:2018-04-14 20:37:18
【问题描述】:
我的 JSON 字符串看起来像:
{
"type": "group",
"logicalOperator": "or",
"conditions":[{
"type": "condition",
"metric": "CTR",
"operator": ">=",
"value": "123"
},
{
"type": "group",
"logicalOperator": "and",
"conditions": [{
"type": "condition",
"metric": "CTR",
"operator": ">=",
"value": "123"
}]
}
]
}
我想将其反序列化为 C# 类(使用 Newtonsoft.JSON)。但是conditions 可以包含group 或condition 这一点对我来说是个问题。
public class Group {
public string logicalOperator { get; set; }
public List<object> conditions { get; set; }
}
public class Condition {
public string metric { get; set; }
public string @operator { get; set; }
public int value { get; set; }
}
我怎样才能摆脱List<object>?蒂亚!
【问题讨论】:
-
请看这个,我已将其标记为可能重复。因为您的问题看起来像条件反序列化。 stackoverflow.com/questions/7816780/…