我有一个JSON,我想访问"rates"
中的键。这是前面提到的JSON:
currency = '''
{
"rates": {
"CNY": 7.6588,
"BGN": 1.9558,
"USD": 1.114
},
"base": "EUR",
"date": "2019-07-24"
}
'''
qwe = json.loads(currency)
当我尝试的时候
for x in qwe['rates']:
print(x)
我得到的价值人民币,BGN,美元没有钥匙。你知道吗
但是当我尝试print(qwe['rates'])
时,我得到了{'CNY': 7.6588, 'BGN': 1.9558, 'USD': 1.114}
我的想法是为每个值指定键
您应该使用.items()dict方法:
要访问该值,必须打印qwe['rates'][x]
输出
相关问题 更多 >
编程相关推荐