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"
import json import simplejson import urllib2 data = urllib2.urlopen(‘www.example.com/url/where/i/get/json/data’).read() j = j = simplejson.loads(data)
Share
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 anitemsmethod. (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).