【发布时间】:2023-01-13 14:58:07
【问题描述】:
我有以下列表/数据框:
[['title1','title1_chapter1','title1_chapter1_section1','title1_chapter1_href1'], ['title1','title1_chapter1','title1_chapter1_section2','title1_chapter1_href2'], ['title1','title1_chapter2','title1_chapter2_section1','title1_chapter2_href1'], ['title1','title1_chapter2','title1_chapter2_section2','title1_chapter2_href2'], ['title2','title2_chapter1','title2_chapter1_section1','title2_chapter1_href1']]
我想将它转换为以下嵌套的 Json,以便它可以在 bootstrap treeview 中使用。
[
{
"nodes": [
{
"nodes": [
{
"text": "title1_chapter1_section1",
"href": "title1_chapter1_href1"
},{
"text": "title1_chapter1_section2",
"href": "title1_chapter1_href2"
}],
"text": "title1_chapter1"
},{
"nodes": [
{
"text": "title1_chapter2_Section1",
"href": "title1_chapter2_href1"
},{
"text": "title1_chapter2_section2",
"href": "title1_chapter2_href2"
}],
"text": "title1_chapter2"
}],
"text": "title1"
},{
"nodes": [
{
"nodes": [
{
"text": "title2_chapter1_section1",
"href": "title2_chapter1_href2"
}],
"text": "title2_chapter1"
}],
"text": "title2"
}
]
那么,如何在 Python 中实现呢?提前致谢。
【问题讨论】:
标签: python json dataframe nested treeview