代码:
import json
import urllib
URL = 'www.xyz.com'
data = json.load(urllib.urlopen(url)
print data
[[{"Region":"Europe", "Details":[{"gender":"male", "name":"john", "age":"24", "status":"Ok"}, {"gender":"female", "name":"Rebecca", "age":"22", "status":"None"}], "country":"Germany"}], [{"Region":"Asia", "Details":[{"gender":"male", "name":"kim", "age":"27", "status":"None"}, {"gender":"male", "name":"jen", "age":"22", "status":"None"}], "country":"China"}]]
# here is what I have tried
for i in data:
for j in i:
for key in j.keys():
dicx = j[key]
for k in dicx:
if isinstance(k, dict) and k['status']=='None':
print (i['region'], k['name'])) #I wnant to store this value in a variable rather than printing.
#this is giving me the following output.
Europe, Rebecca
Asia, kim
Asia, jen
场景:从上面的数据,我想检查是否在所有的“地区”(键)如果“状态”(键)是“确定”(值)或“无”(值),如果“状态”(键)是“无”(值),那么它应该返回我的细节(值)的特定“地区”(键)连同“名称”(键)。你知道吗
例如:- 期望输出(参考上述数据)
Europe, Rebecca
Asia, (kim, jen)
任何帮助都将不胜感激。你知道吗
这很难看,但你可能想问:
编辑#1:
输出:
有3个区域的示例:
相关问题 更多 >
编程相关推荐