After doing a rest api call and storing result as json file contents of json file look as follows:
["x","y","z"]
I need to use python script to iterate through each item and print it out.
I have the following snippet of code which does error out.
with open('%s/staging_area/get_label.json' % cwd) as data_file:
data = json.load(data_file)
for item in data:
print data [item]
Error I am getting is as follows:
Traceback (most recent call last):
File "Untitled 8.py", line 33, in <module>
print data [item]
TypeError: list indices must be integers, not unicode
What am I missing? Thank you for your help!
for item in data: print itemfor item in data: print itemorfor index in range(len(data)): print data[index]. (Hopefully it’s obvious why the first one is better.)