1. json内容
{
"webm":{
"video": "libvp8",
"audio": "libvorbis"
},
"h264": {
"video": "libx264",
"audio": "libfaac"
},
"ogg": {
"video": "libtheora",
"audio": "libvorbis"
}
}
2. 解析
import json
if __name__ == '__main__':
file_name = '1.json'
json_file = json.loads(open(file_name).read())
print("--遍历访问:")
for i in json_file:
print i, ':'
for k in json_file[i]:
print ' ', k, json_file[i][k]
print("\n\n--直接访问:")
print json_file['webm']['audio']
print json_file['ogg']
json_file['h264']['color'] = [0, 255, 0, 128]
with open("3.json","w") as f:
json.dump(json_file, f, indent=4, sort_keys=False)