2016-04-28 136 views
-2

我試圖從提取整數值「計數」每個鍵下面和我惹麻煩用繩子指標的誤差。有人可以提供這樣做的方法從JSON整數?提取使用Python 2.7

"comments":[ 
    { 
     "name":"Courtneylee", 
     "count":97 
    }, 
    { 
     "name":"Geraldine", 
     "count":96 
    }, 
    { 
     "name":"Aisling", 
     "count":96 
    }, 
    { 
     "name":"Millar", 
     "count":93 
    }, 
    { 
     "name":"Aeryn", 
     "count":92 
    }, 
    { 
     "name":"Emilylee", 
     "count":92 
    }, 
    { 
     "name":"Clodagh", 
     "count":92 
    }, 
    { 
     "name":"Madelaine", 
     "count":91 
    }, 
    { 
     "name":"Amyrose", 
     "count":89 
    }, 
    { 
     "name":"Kael", 
     "count":85 
    }, 
    { 
     "name":"Ngonidzashe", 
     "count":83 
    }, 
    { 
     "name":"Zayn", 
     "count":83 
    }, 
    { 
     "name":"Jordy", 
     "count":80 
    }, 
    { 
     "name":"Tyane", 
     "count":78 
    }, 
    { 
     "name":"Hussnan", 
     "count":78 
    }, 
    { 
     "name":"Karly", 
     "count":70 
    }, 
    { 
     "name":"Matej", 
     "count":70 
    }, 
    { 
     "name":"Reena", 
     "count":68 
    }, 
    { 
     "name":"Abigayle", 
     "count":68 
    }, 
    { 
     "name":"Karamvir", 
     "count":67 
    }, 
    { 
     "name":"Kaleigh", 
     "count":66 
    }, 
    { 
     "name":"Roba", 
     "count":65 
    }, 
    { 
     "name":"Harjyot", 
     "count":65 
    }, 
    { 
     "name":"Attila", 
     "count":64 
    }, 
    { 
     "name":"Dharam", 
     "count":62 
    }, 
    { 
     "name":"Marcin", 
     "count":56 
    }, 
    { 
     "name":"Ruaidhri", 
     "count":56 
    }, 
    { 
     "name":"Adenn", 
     "count":51 
    }, 
    { 
     "name":"Saschamarie", 
     "count":50 
    }, 
    { 
     "name":"Rylie", 
     "count":49 
    }, 
    { 
     "name":"Alieu", 
     "count":48 
    }, 
    { 
     "name":"Caidy", 
     "count":43 
    }, 
    { 
     "name":"Kaila", 
     "count":40 
    }, 
    { 
     "name":"Declain", 
     "count":39 
    }, 
    { 
     "name":"Owyn", 
     "count":37 
    }, 
    { 
     "name":"Gurthar", 
     "count":35 
    }, 
    { 
     "name":"Brandon", 
     "count":33 
    }, 
    { 
     "name":"Mustafa", 
     "count":32 
    }, 
    { 
     "name":"Dion", 
     "count":31 
    }, 
    { 
     "name":"Meenal", 
     "count":22 
    }, 
    { 
     "name":"Kyan", 
     "count":20 
    }, 
    { 
     "name":"Karis", 
     "count":18 
    }, 
    { 
     "name":"Christabel", 
     "count":12 
    }, 
    { 
     "name":"Kerryanne", 
     "count":12 
    }, 
    { 
     "name":"Martha", 
     "count":10 
    }, 
    { 
     "name":"Helena", 
     "count":9 
    }, 
    { 
     "name":"Rumaysa", 
     "count":7 
    }, 
    { 
     "name":"Rosalind", 
     "count":5 
    }, 
    { 
     "name":"Florin", 
     "count":4 
    }, 
    { 
     "name":"Melisa", 
     "count":3 
    } 
    ] 
} 
+0

你能提供您所使用的代碼和追蹤? – glibdud

+0

的JSON是無效的。 – MCSH

回答

-1
data = {'comments':[...]} #Your dict 
for item in data['comments']: 
    print item['count'] #Whatever operation you want with your number 
+0

的OP沒有提到他有一本字典,這個問題的標題表明他有一個JSON – bashrc

+0

可以請你發佈你正在使用的代碼和你正在獲得的錯誤? –

+0

import json import url LIB URL =的raw_input( '輸入 - ') 的Java =了urllib.urlopen(URL).read() 打印的Java 信息= json.loads(JAVA) #PRINT信息 爲項信息: 打印項目['評論'] [{'count'}] [0] –