获取json所有末端节点方法参考,遍历json节点 From https://segmentfault.com/q/1010000002524168
#!/usr/bin/env python
#coding:utf8
# Author : tuxpy
# Email : q8886888@qq.com
# Last modified : 2015-01-31 16:55:01
# Filename : t1.py
# Description :
import pymongo
def get_all_key(obj):
if isinstance(obj, dict):
for key, value in obj.items():
print key
if isinstance(value, (list, dict)):
get_all_key(value)
if isinstance(obj, list):
for item in obj:
if isinstance(item, (dict, )):
get_all_key(item)
db = pymongo.Connection().test
document = dict(db.test.find_one())
del document['_id']
get_all_key(document)