【发布时间】:2022-01-07 20:21:15
【问题描述】:
我有一个 json 字符串。
根据类别,json 字符串中有多个子类别。 我想把它们全部结合起来。 它应该始终给出更高级别的最后一个子级别的 Id。
示例:
Id - Name
-- ----------
1239 - Accessory> Jewelery > wristband> Silver wristband
谁能帮帮我。谢谢
{
"categories": [
{
"id": 368,
**"name": "Accessory ",**
"parentId": null,
"subCategories": [
{
"id": 396,
**"name": "Jewelery ",**
"parentId": 368,
"subCategories": [
{
"id": 397,
**"name": "wristband",**
"parentId": 396,
"subCategories": [
{
"id": 1238,
"name": "Gold wristband",
"parentId": 397,
"subCategories": []
},
{
**"id": 1239,**
"name": "Silver wristband",
"parentId": 397,
"subCategories": []
},
{
"id": 2845,
"name": "Steel wristband",
"parentId": 397,
"subCategories": []
},
{
"id": 3171,
"name": "Pearl wristband",
"parentId": 397,
"subCategories": []
},
{
"id": 3883,
"name": "diamond wristband",
"parentId": 397,
"subCategories": []
}
]
}
]
}
]
}
]
}
这是我的课
public class SubCategory
{
public int id { get; set; }
public string name { get; set; }
public int parentId { get; set; }
public List<object> subCategories { get; set; }
}
public class Category
{
public int id { get; set; }
public string name { get; set; }
public object parentId { get; set; }
public List<SubCategory> subCategories { get; set; }
}
public class Root
{
public List<Category> categories { get; set; }
}
【问题讨论】:
-
您尝试过什么?您在尝试转换 JSON 时是否有任何错误可以分享?
-
我给了一个样本。我想知道我该怎么做。
-
哦,感谢@huMpty duMpty 的编辑,我意识到我的答案不是你问的,我会尽快编辑它