【发布时间】:2015-04-23 20:59:21
【问题描述】:
我是 python 的初学者。我的 json 文件是:
{
"dog": {
"dog1": ["cat1", "cat2"],
"dog2": ["cat2", "cat1"]
},
"cat": {
"cat1": ["dog1", "dog2"],
"cat2": ["dog1", "dog2"]
}
}
我将 json 文件保存到变量 x 中:
import json
f = open(jsonfile, 'r')
x = json.load(f)
f.close()
现在我想制作两本名为“cat”和“dog”的字典。我该怎么做? P.s 每次有人调用程序时,文件 json 都可能不同。特别是,它可以有更多或更少的狗或猫。
【问题讨论】:
标签: python json dictionary