[英]Python - get list of keys in nested dictionary
我有一个看起来像这样的JSON文件:
{
"meta": {
"limit": 25,
"cache-expiry": 3600
},
"objects": [
{
"name": "Elements Automotive",
"locality": "Dallas",
"street_address": "8700 Sovereign Row",
"cuisines": [],
"postal_code": "75247",
"categories": [
"other"
],
"has_menu": false,
"country": "United States",
"lat": 32.8191949123164,
"id": "000e090545789efeca0c",
"website_url": "http://elementsautomotive.com/",
"resource_uri": "/v1_0/venue/000e090545789efeca0c/"
}
]
}
如何从对象中获取键列表(“名称”,“位置”等)?
编辑:对不起,键都是统一的-我只是剪掉了其中一些,以使代码/帖子简短。
data["objects"][0].keys()
['cuisines', 'postal_code', 'lat', 'id', 'categories', 'name', 'locality', 'country', 'street_address', 'has_menu', 'website_url', 'resource_uri']
with open('jsondatafile') as fp:
data = json.load(fp)
print list(data['objects'][0])
应该做到这一点...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.