python for循环读取复合json数据,python:读取json和循环字典

这篇博客介绍了如何使用Python的json模块读取和遍历复合JSON数据。通过示例展示了使用for循环遍历字典的方法,并提出了关于循环变量命名和直接使用json.load的优化建议。
摘要由CSDN通过智能技术生成

I'm learning python and i loop like this the json converted to dictionary: it works but is this the correct method? Thank you :)

import json

output_file = open('output.json').read()

output_json = json.loads(output_file)

for i in output_json:

print i

for k in output_json[i]:

print k, output_json[i][k]

print output_json['webm']['audio']

print output_json['h264']['video']

print output_json['ogg']

here the JSON:

{

"webm":{

"video": "libvp8",

"audio": "libvorbis"

},

"h264": {

"video": "libx264",

"audio": "libfaac"

},

"ogg": {

"video"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值