I have a JSON object, retrieved from Twitter API through tweepy that contains the twitter object, looking like this:
{"created_at": "Tue Aug 01 16:23:56 +0000 2017",
"id": xxx,
"id_str": “xxx”,
"full_text": “xxxxx”,
"truncated": false,
"display_text_range": [0, 85],
"entities": {"hashtags": [], "symbols": [], "user_mentions": [], "urls": [],
"media": [{"id": xxxx, "id_str": “xxxxx”, "indices": [86, 109],
"media_url": “xxxxx”, Etc…..
I am trying to read three values into a dataframe
df_tweet = []
for json_string in json_str:
tweet_id = json_string['id']
retweet_count = json_string['retweet_count']
favorite_count = json_string['favorite_count']
df_tweet.append({'tweet_id':int(id),
'retweet_count':int(retweet_count),
'favorite_count':int(favorite_count)
})
I get the error“ string indices must be integers”. I understand that “id” and the other values in the JSON response are not an index and I can’t read out the data like this. Reading this question: Why am I seeing "TypeError: string indices must be integers"? Is there anything that can be done at this point, or do I need to make changes on how I get the JSON in the first place?