开发者社区> 问答> 正文

怎么实现node 子节点

观察以下JSON数据结构,设计Node类和⼯具⽅法 Node NodeUtils.getNode(List n odes, String path) ,通过该⽅法可以获取nodes中的Node.path与输⼊参数path相同的节点

[ { "path": "level0_0/", "value": "value", "children": [ { "path": "level0_0/level1_0/", "value": "value", "children": [ { "path": "level0_0/level1_0/level2_0", "value": "value", "children": [] },{ "path": "level0_0/level1_0/level2_1", "value": "value", "children": [] },{ "path": "level0_0/level1_0/level2_1", "value": "value", "children": [] 3 | } ] },{ "path": "level0_0/level1_1/", "value": "value", "children": [ { "path": "level0_0/level1_1/level2_0", "value": "value", "children": [] },{ "path": "level0_0/level1_1/level2_1", "value": "value", "children": [] },{ "path": "level0_0/level1_1/level2_1", "value": "value", "children": [] } ] } ] },{ "path": "level0_1/", "value": "avaluerg", "children": [] } ] 实现效果(伪代码) List nodes = JSON.parse(str); Node node = NodeUtils.getNode(nodes, "level0_0/level1_1/level2_1"); print(JSON.toString(node)); //运行结果 { "path": "level0_0/level1_1/level2_1", "value": "value", "children": [] } 4 |

展开
收起
何时定123 2020-05-19 10:54:15 950 0
1 条回答
写回答
取消 提交回答
  • 亲,代码格式可以调整一下吗~

    image.png

    2020-05-19 14:10:26
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
探究 Node.js 的服务端之路 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载