How to access content from a json file?

0

I have a JSON file of information extracted from Twitter through the tweepy library, a piece of the contents of the file is as follows:

Status(extended_entities={'media': [{'source_user_id': 3383675067, 'url': 'https://t.co/x03h8R996T', 'media_url_https': 'https://pbs.twimg.com/media/DPkZCyZX0AAB6QP.jpg', 'type': 'photo', 'display_url': 'pic.twitter.com/x03h8R996T', 'source_status_id': 934805944525099008, 'id': 934805933334712320, 'indices': [100, 123], 'id_str': '934805933334712320', 'media_url': 'http://pbs.twimg.com/media/DPkZCyZX0AAB6QP.jpg', 'sizes': {'small': {'w': 512, 'h': 288, 'resize': 'fit'},....

The content is all within this method Status

How can I get some content within this file, for example, "'id_str': '934805933334712320'" ?

    
asked by anonymous 06.06.2018 / 05:17

2 answers

0

Can you access the contents of the file?

If you can, it's not too complicated. I may be seeing badly, it seems to me that it is a dictionary and the key media has a list value. So, you access the 1st element (I do not see any element anymore) and this first element is a dictionary, so you just have to access the key name. I think the end result would be this:

extended_entities['media'][0]['id_str']
    
06.06.2018 / 05:30
0

The file is returning a JSON file that needs to be interpreted.

 import json
 j = json.loads('{"id_str": "934805933334712320", "media_url": "http://pbs.twimg.com/media/DPkZCyZX0AAB6QP.jpg"}')

 print j['id_str']
    
06.06.2018 / 05:31