假设我的json响应如下所示:
{
"classifier_id" : "12345",
"url" : "https://something.com",
"text" : "text",
"top_class" : "class1",
"classes" : [ {
"class_name" : "car",
"confidence" : 0.9862312904583641
}, {
"class_name" : "bus",
"confidence" : 0.013768709541636032
} ]
}
底层GET请求为
callIBM = requests.get(
url="https://something.com",
params={
"text": update.message.text,
},
headers={
"Authorization": "XXX",
},
)
我想用python解析结果
我试过:
ibmscore1 = '{}'.format(callIBM.json()["classes"][0]["class_name"]["confidence"])
ibmscore2 = '{}'.format(callIBM.json()["classes"][1]["class_name"]["confidence"])
但它不起作用。能不能请一位Python新手帮忙
您正试图访问
class_name
内的confidence
,但class_name
不是字典尝试:
相关问题 更多 >
编程相关推荐