源数据:
{ "split_index":3, "split_feture":"abc", "left_child":{ "split_index":4, "split_feture":"abc1", "left_child":{ "split_index":4, "split_feture":"abc1", "left_child":{ "split_index":6, "split_feture":"abc1", "left_child":{ "split_index":7, "split_feture":"abc1", "left_child":{ "leaf_index":119, "leaf_feature":"efg19" }, "right_child":{ "leaf_index":110, "leaf_feature":"efg10" } }, "right_child":{ "split_index":8, "split_feture":"abc1", "left_child":{ "leaf_index":18, "leaf_feature":"efg1" }, "right_child":{ "leaf_index":18, "leaf_feature":"efg1" } } }, "right_child":{ "split_index":9, "split_feture":"abc1", "left_child":{ "leaf_index":18, "leaf_feature":"efg1" }, "right_child":{ "leaf_index":18, "leaf_feature":"efg1" } } }, "right_child":{ "split_index":10, "split_feture":"abc1", "left_child":{ "leaf_index":18, "leaf_feature":"efg1" }, "right_child":{ "leaf_index":18, "leaf_feature":"efg1" } } }, "right_child":{ "split_index":11, "split_feture":"abc2", "left_child":{ "split_index":12, "split_feture":"abc1", "left_child":{ "split_index":13, "split_feture":"abc1", "left_child":{ "leaf_index":30, "leaf_feature":"efg4" }, "right_child":{ "leaf_index":32, "leaf_feature":"efg5" } }, "right_child":{ "split_index":14, "split_feture":"abc1", "left_child":{ "leaf_index":18, "leaf_feature":"efg1" }, "right_child":{ "leaf_index":19, "leaf_feature":"efg1" } } }, "right_child":{ "split_index":4, "split_feture":"abc1", "left_child":{ "leaf_index":23, "leaf_feature":"efg3" }, "right_child":{ "leaf_index":21, "leaf_feature":"efg1" } } }}
Java数据结构定义
对象内判断方法:
java 实现json转二叉树结构体,备注:fastjson这里转java对象会失败,原因是又对象嵌套
二叉树获取所有左侧叶子节点:
同理获取所有右侧叶子节点:
源代码: