【发布时间】:2021-02-02 11:49:31
【问题描述】:
我需要你的帮助来从完整的 URL 中获取父子 URL 列表,可能是递归使用。 例如,下面是平面结构中的 URL。我必须使用子结构的内部级别以父子形式解析。
- https://domain/UrlA/UrlA_L1/UrlA_L1_L2
- https://domain/UrlA/UrlA_L1/UrlA2_L1_L2
- https://domain/UrlB/UrlB_L1/UrlB_L1_L2
- https://domain/UrlC/UrlC_L1/UrlC_L1_L2
- https://domain/UrlD/UrlD_L1/UrlD_L1_L2/UrlD_L1_L2_L3
- https://domain/UrlE/UrlE_L1/UrlE_L1_L2/UrlE_L1_L2_L3
- https://domain/UrlF/UrlF_L1/UrlF_L1_L2/UrlF_L1_L2_L3
进入具有父子关系的 URL 列表。
public class HtmlSiteMap
{
public string Url { get; set; }
public string PageTitle { get; set; }
public int UrlLevel { get; set; }
public List<HtmlSiteMap> Childrens { get; set; }
}
我的预期输出
{
Url: https://domain/UrlA,
PageTitle : UrlA,
UrlLevel : 0 ,
Childrens : {
Url : https://domain/UrlA/UrlA_L1,
PageTitle : UrlA_L1,
UrlLevel : 1,
Childrens : {
Url : https://domain/UrlA/UrlA_L1/UrlA_L1_L2,
PageTitle : UrlA_L1_L2,
UrlLevel : 2,
Childrens : null
},
{
Url : https://domain/UrlA/UrlA_L1/UrlA2_L1_L2,
PageTitle : UrlA2_L1_L2,
UrlLevel : 2,
Childrens : null
}
},
Url: https://domain/UrlB,
PageTitle : UrlB,
UrlLevel : 0 ,
Childrens : {
Url : https://domain/UrlB/UrlB_L1,
PageTitle : UrlB_L1,
UrlLevel : 1,
Childrens : {
Url : https://domain/UrlB/UrlB_L1/UrlB_L1_L2,
PageTitle : UrlB_L1_L2,
UrlLevel : 2,
Childrens : null
}
}
.................
.................
..................
}
我试图通过拆分和递归来实现。但无法得到结果。您的帮助将不胜感激。
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api