2017-08-15 4 views
-2

私はこのデータをAPI経由で取得しており、そこにあるすべての「信頼」スコアを引き出したいと考えています。どのように私はそれをやって行くだろう:この(json looking)データをどのように照会しますか?

{ 
    "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" 
    } 
    ] 
} 

私はdata["confidence"]のようなものをやってみましたが、自信の数字を引っ張っていないようでした。 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) 
+1

このデータを取得するコードを表示してください。 –

+0

[JSONファイルの値の解析?](https://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file) –

+0

jsonではありません。それは最初に "b '"を持っています。 – semiflex

答えて

1

あなたの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" 
    } 
    ] 
} 

あなたはこのコードを使用することができますcondidence抽出するには:

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) 
関連する問題