我有以下JSON格式:
{
"name": "detail_check",
"count": 1,
"results": {
"pharmacies": [
{
"name": "Akar Eczanesi",
"phone": "+90 (216) 575-71-68"
}
]
}
}
有时,药房不存在“电话”密钥,我得到了这个例外:
"KeyError: 'phone'"
在这里添加控件的最简单方法是什么?我的代码如下所示:
data = json.load(urllib.urlopen(iriToUri('https://yadayada')))
if "212" in data['results']['pharmacies'][0]['phone']:
stuff
else:
some other stuff