我有一个这样的 JSON 列表(这是一个 JSON 响应,下面是我做的之后json.loads)
[{'status': 'ok', 'slot': None, 'name': 'blah', 'index': 0, 'identify': 'off',
'details': None, 'speed': None, 'temperature': None}, {'status': 'ok', 'slot':
None, 'name': 'blah0', 'index': 0, 'identify': 'off', 'details': None,
'speed': None, 'temperature': None}, {'status': 'ok', 'slot': None, 'name':
'blah1', 'index': 1, 'identify': 'off', 'details': None, 'speed': None,
'temperature': None}, {'status': 'ok', 'slot': None, 'name': 'blah2',
'index': 2, 'identify': 'off', 'details': None, 'speed': None, 'temperature':
None}, {'status': 'ok', 'slot': None, 'name': 'blah3', 'index': 3,
'identify': 'off', 'details': None, 'speed': None, 'temperature': None}]
我想这两个name和status如果列表中,name='blah' or 'blah0' or 'blah1' or 'blah2' or 'blah3' 从本质上讲,所有我想要存储的所有比赛name,并status在不同的变量在其他地方使用它。(可以动态创建变量或静态分配它们也适用于我)
我试过这个,但似乎不像我想要的那样工作。
for value in data:
if value['name'] in ['blah', 'blah0', 'blah1', 'blah2', 'blah3']:
print(value['name'], value['status'])
这会将name和status作为字符串打印在另一行下方。但我希望将每个名称和状态分配给一个变量,以便我以后可以使用它。任何帮助深表感谢!
皈依舞
青春有我
相关分类