我有一个包含下面列出的货币的 json 对象,我需要将其转换为我的模型并将其保存到数据库中。还有一种方法可以一次性保存模型列表吗?
{
"results": {
"ALL": {
"currencyName": "Albanian Lek",
"currencySymbol": "Lek",
"id": "ALL"
},
"KWD": {
"currencyName": "Kuwaiti Dinar",
"id": "KWD"
},
"LSL": {
"currencyName": "Lesotho Loti",
"id": "LSL"
},
"MYR": {
"currencyName": "Malaysian Ringgit",
"currencySymbol": "RM",
"id": "MYR"
},
"MUR": {
"currencyName": "Mauritian Rupee",
"currencySymbol": "₨",
"id": "MUR"
}
}
}
我试过这个:
for key,value in currencies.results :
#print(currency)
#print(value)
但是,我收到以下错误:
”Too many attribures to unpack, expected 2
有人可以帮我弄这个吗?
我觉得应该是这样的:
results = currencies.get('results')
for key, value in results.items(): # for python3
print(key, value)
for key, value in results.iteritems(): # python2.7
print(key, value)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句