Python 如何查询此(json外观)数据?
我有这些数据是通过api获得的,我想获取其中所有的“信心”分数。我该怎么做:Python 如何查询此(json外观)数据?,python,json,Python,Json,我有这些数据是通过api获得的,我想获取其中所有的“信心”分数。我该怎么做: { "time": 765, "annotations": [ { "start": 106, "end": 115, "spot": "customers", "confidence": 0.7198, "id": 234206, "title": "Customer", "uri": "h''ttp://en.wik
{
"time": 765,
"annotations": [
{
"start": 106,
"end": 115,
"spot": "customers",
"confidence": 0.7198,
"id": 234206,
"title": "Customer",
"uri": "h''ttp://en.wikipedia.org/wiki/Customer",
"label": "Customer"
},
{
"start": 116,
"end": 122,
"spot": "online",
"confidence": 0.6313,
"id": 41440,
''"title": "Online and offline",
"uri": "http://en.wikipedia.org/wiki/Online_and_offline",
"label": "Online"
},
{
"start": 138,
"end": 143,
"s''pot": "small",
"confidence": 0.7233,
"id": 276495,
"title": "Small business",
"uri": "http://en.wikipedia.org/wiki/Small_business",
"label''": "Small business"
}
]
}
我试着做一些事情,比如数据[“信心”]
,但它似乎没有拉动信心数据。如何在Python中提取信心数据?先谢谢你
这是检索数据的代码:
import requests
api_key = INSERT API KEY
content_urls = "http://www.startupdonut.co.uk/sales-and-marketing/promote-your-business/using-social-media-to-promote-your-business"
url = "https://api.dandelion.eu/datatxt/nex/v1/?lang=en &url="+content_urls+"&token=" + api_key
request = requests.get(url)
for data in request:
print (data)
您的API响应数据如下所示:
{
"time": 765,
"annotations": [
{
"start": 106,
"end": 115,
"spot": "customers",
"confidence": 0.7198,
"id": 234206,
"title": "Customer",
"uri": "h''ttp://en.wikipedia.org/wiki/Customer",
"label": "Customer"
},
{
"start": 116,
"end": 122,
"spot": "online",
"confidence": 0.6313,
"id": 41440,
''"title": "Online and offline",
"uri": "http://en.wikipedia.org/wiki/Online_and_offline",
"label": "Online"
}
]
}
要提取条件,可以使用以下代码:
import json
# ... request formation code goes here
response = requests.get(url)
data = response.json() # OR data = json.loads(response.content)
confidence_values = []
for annotation in data['annotations']:
confidence_values.append(annotation.get('confidence'))
print(confidence_values)
请显示检索此数据的代码。可能重复的不是json。它的开头有一个“b”。