python解析任意json
from future import print_function
import json
def dict_generator(indict, pre=None):
pre = pre[:] if pre else []
if isinstance(indict, dict):
for key, value in indict.items():
if isinstance(value, dict):
if len(value) == 0:
yield pre+[key, ‘{}’]
else:
for d in dict_generator(value, pre + [key]):
yield d
elif isinstance(value, list):
if len(value) == 0:
yield pre+[key, ‘[]’]
else:
for v in value:
for d in dict_generator(v, pre + [key]):
yield d
elif isinstance(value, tuple):
if len(value) == 0:
yield pre+[key, ‘()’]
else:
for v in value:
for d in dict_generator(v, pre + [key]):
yield d
else:
yield pre + [key, value]
else:
yield indict
if name == “main”:
sJOSN = ‘’
sValue = json.loads(sJOSN)
for i in dict_generator(sValue):
print(’.’.join(i[0:-1]), ‘:’, i[-1])
相关文章
- Python-使用pickle和json进行序列化和反序列化
- Python Http请求json解析库
- python之迭代器与生成器
- 实例解析java + jQuery + json工作过程(获取JSON数据)
- Python 字符串_python 字符串截取_python 字符串替换_python 字符串连接
- Jenkins部署python-flask后端项目,持续集成(jinkins配置python虚拟环境)
- [Python] Check for None (Null) in Python
- [Python] Create a Log for your Python application
- Python视觉深度学习系列教程 第一卷 第9章 优化方法和正则化
- Python的IDE:基于Eclipse/MyEclipse软件的PyDev插件配置python的开发环境(不同python项目加载不同版本的python)—从而实现Python编程图文教程之详细攻略
- Python 和前端开发的入门难度如何?
- 〖Python自动化办公篇⑲〗 - python实现邮件自动化 - 邮件发送
- 构建 Python C 扩展模块
- 【华为机试真题 Python实现】密钥格式化
- Python爬虫:PyExecJS在python中运行javascript代码
- python 将一个JSON 字典转换为一个Python 对象
- Python: yield, python 实现tail -f
- python中读取json文件报错,TypeError:the Json object must be str, bytes or bytearray,not ‘TextIOWrapper’
- python项目环境的导出、导入
- python glances来监控linux服务器CPU 内存 IO使用
- 【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
- 【Python基础】python爬虫之异步网络爬虫ǃ
- 【异常】前端ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- python工具方法 17 labelme标注的json文件转voc数据再转训练列表