How to access content from a json file?

Asked

Viewed 469 times

1

I have a JSON file of information extracted from Twitter through the library tweepy, a piece of file content 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 inside this file, for example, "'id_str': '934805933334712320'"?

  • Please put your code in the question so we can see how you’re doing. What you presented to us is not a JSON, so you’re probably misinterpreting something.

2 answers

1

You can access the contents of the archive?

If you can, it’s not too complicated. I may be seeing wrong, it seems to me it’s a dictionary and the key media is worth a list. So, you access the first element (I don’t see any more elements) and this first element is a dictionary, so just access the key name. I think the end result would be this:

extended_entities['media'][0]['id_str']

1

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']
  • And the rest of json ? Because in your example there is only the part that starts at id_str ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.