Reputation: 777
import json
import simplejson
import urllib2
data = urllib2.urlopen('www.example.com/url/where/i/get/json/data').read()
j = ""
j = simplejson.loads(data)
dump_data=simplejson.dumps(j)
for data in j["facets"]:
print data.items()
print "\n----------------\n"
Upvotes: 0
Views: 3567
Reputation: 16037
Title contains the answer
j["facets"]
is probably a list of string items
Upvotes: 1
Reputation: 310069
The error message says it all. Clearly j["facets"]
is an iterable which contains at least some strings instead of containing some other datatype which has an items
method. (maybe you expected a dict)?
Try printing j["facets"]
to see what you're actually getting there. Then you might be able to figure out why you're getting a string instead of the expected object (dict
).
Upvotes: 5