您需要一个树搜索算法:
def locateByName(e,name): if e.get('name',None) == name: return e for child in e.get('children',[]): result = locateByName(child,name) if result is not None: return result return None
现在,您可以使用此递归函数查找所需的元素:
node = locateByName(output_json, 'BoxDet')print node['name'],node['Ids']
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)