采取像这样的嵌套递归 JSON 片段,它可以继续到任何深度:
{
"Id": null,
"Foos": [
{
"FooId": 1,
"FooName": "ABC",
"Foos": [
{
"FooId": 2,
"FooName": "DEF",
"Foos": null
},
{
"FooId": 3,
"FooName": "GHI",
"Foos": [
{
"FooId": 4,
"FooName": "JKL",
"Foos": null
},
{
"FooId": 5,
"FooName": "MNO",
"Foos": [
{
"FooId": 6,
"FooName": "PQR",
"Foos": null
},
{
"FooId": 7,
"FooName": "STU",
"Foos": null
}
]
}
]
}
]
}
]
}
使用 JSON.NET 我可以将其映射到这样的结构中:
public class Root {
public string Id { get; set; }
public List<Foo> Foos { get; set; }
}
public class Foo {
public int FooId { get; set; }
public string FooName { get; set; }
public List<Foo> Foos { get; set; }
}
到目前为止一切顺利......但现在我需要从层次结构的底部向上工作(从 FooId = 5 的子级开始)然后回到根目录。我该如何有效地解决这个问题?
阿晨1998
HUX布斯
随时随地看视频慕课网APP
相关分类