我试图从python list对象中的特定列检索值,HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"tables": [
{
"name":"PrimaryResult",
"columns": [
{
"name":"Category",
"type":"string"
},
{
"name":"count_",
"type":"long"
}
],
"rows": [
[
"Administrative",
20839
],
[
"Recommendation",
122
],
[
"Alert",
64
],
[
"ServiceHealth",
11
]
]
}
]
}
有几百列,我想读取特定的列和行值,result=requests.get(url, params=params, headers=headers, verify=False)
index_category = (result.json()['tables'][0]['columns']).index('Category')
我犯了什么错?
ValueError: 'Category' is not in list
for column in range(0,columns):
if ((result.json()['tables'][0]['columns'][column]['name']) == 'Category'):
index_category = column
for row in range(0,rows):
print(result.json()['tables'][0]['rows'][row][index_category])