TypeError: 'int' object is not subscriptable

crhodes2

crhodes

Posted on July 25, 2018

TypeError: 'int' object is not subscriptable

So here is the situation: I have a json object, requested from a 3rd party source, that has a list of items. 14 of them.

I am able to display them all by count: ie. 0,1,2,3...13. This is what I used to display them.

x = my_request["jsonObject"]["items"]
for ex in range(x):
print(ex)

But each one of these items have additional attributes from within and I want to access at least one item's attribute. Let's say the one I want to access is "item_color", and according to the jSON file it is nested with other attribute.

This was my attempt:
for ex in x:
print(ex["itemInfo"]["color"])

But I get an 'int' object is not subscriptable.

Is there a way for me to display the attribute that I want to display on the console, just like how I displayed all the items by count?

Please find a screenshot of the json object I am manipulating below to get a better idea.

https://www.dropbox.com/s/apao25r9j2b22ir/Screen%20Shot%202018-07-25%20at%204.07.36%20PM.png?dl=0

💖 💪 🙅 🚩
crhodes2
crhodes

Posted on July 25, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related