Reputation: 13
Here is my dictionary:
{"draws":{"draw":[{"drawTime":"01-01-2017T22:00:00","drawNo":1771,"results":[3,3,4,9,2,9,1]}]}}
I want to get the "results" from this nested dictionary but an error keeps appearing that the list indices must be integers. Basically I want to get [3,3,4,9,2,9,1]. Any help would be greatly appreciated.
Here is my code:
import urllib2
import json
for dt in range (1,31):
url = 'http://applications.opap.gr/DrawsRestServices/proto/drawDate/%s-01-2017.json'%dt
json_obj = urllib2.urlopen(url)
data = json.load(json_obj)
#num_array = list(data['draws']['draw'])
data1= data['draws']['draw']
print data1['results']
Upvotes: 0
Views: 47
Reputation: 4279
You missed a list.
{"draws":{"draw":[{"drawTime":"01-01-2017T22:00:00","drawNo":1771,"results":[3,3,4,9,2,9,1]}]}}
Look closely at "draw", its value is a list of dicts, so what you need is
data['draws']['draw'][0]['results']
Upvotes: 2