Arrays 使用python 3获取json数组的密钥
我试图在json数组中获取一个键的值 以下是我的Json的结构和变量的输出:Arrays 使用python 3获取json数组的密钥,arrays,json,python-3.x,Arrays,Json,Python 3.x,我试图在json数组中获取一个键的值 以下是我的Json的结构和变量的输出: databill.append({ "bloc":BlocNum, "subBlocNum":subBlocNum, "detection":TextExtraction, }) print(databill) [{'bloc': 1, 'subBlocNum': 0, 'detection': 'Nr
databill.append({
"bloc":BlocNum,
"subBlocNum":subBlocNum,
"detection":TextExtraction,
})
print(databill)
[{'bloc': 1, 'subBlocNum': 0, 'detection': 'Nr TraNSaCt. A. 0N'},
{'bloc': 1, 'subBlocNum': 1, 'detection': '17S'},
{'bloc': 2, 'subBlocNum': 2, 'detection': 'S0LDE'},
{'bloc': 2, 'subBlocNum': 3, 'detection': '35. 34'},
{'bloc': 3, 'subBlocNum': 4, 'detection': 'ANCIEN S0LDE .'},
{'bloc': 3, 'subBlocNum': 5, 'detection': '41. 73'}]
我想得到bloc3和subBlocNum:5的键“detection”的值
这里的值是41.73,不知道列表中是否有多个JSON对象具有所需的值,那么我将使用如下列表理解:
databill = [{'bloc': 1, 'subBlocNum': 0, 'detection': 'Nr TraNSaCt. A. 0N'},
{'bloc': 1, 'subBlocNum': 1, 'detection': '17S'},
{'bloc': 2, 'subBlocNum': 2, 'detection': 'S0LDE'},
{'bloc': 2, 'subBlocNum': 3, 'detection': '35. 34'},
{'bloc': 3, 'subBlocNum': 4, 'detection': 'ANCIEN S0LDE .'},
{'bloc': 3, 'subBlocNum': 5, 'detection': '41. 73'}]
[d['detection'] for d in databill if d['bloc']==3 and d['subBlocNum']==5]
['41.73']
如果不知道列表中是否有多个JSON对象具有所需的值,那么我将使用如下列表理解:
databill = [{'bloc': 1, 'subBlocNum': 0, 'detection': 'Nr TraNSaCt. A. 0N'},
{'bloc': 1, 'subBlocNum': 1, 'detection': '17S'},
{'bloc': 2, 'subBlocNum': 2, 'detection': 'S0LDE'},
{'bloc': 2, 'subBlocNum': 3, 'detection': '35. 34'},
{'bloc': 3, 'subBlocNum': 4, 'detection': 'ANCIEN S0LDE .'},
{'bloc': 3, 'subBlocNum': 5, 'detection': '41. 73'}]
[d['detection'] for d in databill if d['bloc']==3 and d['subBlocNum']==5]
['41.73']
请分享你的代码。我有json部分是因为代码太长。请分享你的代码。我有json部分是因为代码太长