【发布时间】:2019-01-28 18:51:39
【问题描述】:
我将来自第三方提供商的 JSON 反序列化为一个对象,并希望查询该对象以查找特定属性中的值。
我的问题是对象有一个属性(Parts),它的值是一个相同类型的列表。
public class RulePartModel
{
public string isExistsUnder { get; set; }
public int State { get; set; }
public string Value { get; set; }
public List<RulePartModel> Parts { get; set; }
}
当 Parts 属性可以有 6 或 7 个级别时,我如何查询此对象以查找特定值?
这是我收到的 JSON 示例:
{
"isExistsUnder": null,
"State": "",
"Value": "CustomElements",
"Parts": [
{
"isExistsUnder": null,
"State": 0,
"Value": "Rule 73",
"Parts": [
{
"isExistsUnder": null,
"State": "",
"Value": "For variable initializations",
"Parts": [
{
"isExistsUnder": null,
"State": "",
"Value": "cupis",
"Parts": [
{
"isExistsUnder": null,
"State":"",
"Value": "randomText1",
"Parts": []
},
{
"isExistsUnder": null,
"State":"",
"Value": "randomText2",
"Parts": []
},
{
"isExistsUnder": null,
"State":"",
"Value": "randomText3",
"Parts": []
}
]
}
}
}
}
【问题讨论】:
-
部件的顶部是否只有一个元素,或者同一级别上可以有多个子部件?
-
同一层级可以有多个子部分。我更新了 json 示例以显示这一点。
标签: c# linq linq-to-objects