Uninote
Uninote
用户根目录
common
guanjin
programming
docs
后端试题
问题讨论

文本解析为树形结构

写一段 PHP 代码,实现将用缩进(可以假定为2个空格)表示的文本解析为树形结构。比如输入为:

a
  b
    c
d
  e

则解析为:

{
    "text": "",
    "children": [
        {
            "text": "a",
            "children": [
                {
                    "text": "b",
                    "children": [
                        {
                            "text": "c",
                            "children": []
                        }
                    ]
                }
            ]
        },
        {
            "text": "d",
            "children": [
                {
                    "text": "e",
                    "children": []
                }
            ]
        }
    ]
}

第一题

已完成-四川省人民医院·成都青城山医院招聘

点赞(0) 阅读(155) 举报
目录
标题