我有txt
文件,并想将内容解析为Json
格式。
我的代码如下:
class Twitter_Tools():
def json_parser(filename):
filename = '\\twitter_data.txt'
cpath = os.getcwd()
realfilename = cpath + filename
print(realfilename)
tweets = []
if(realfilename != None):
try:
with open(realfilename, "r") as reader:
for line in reader:
tweet = json.loads(line)
tweets.append(tweet)
except IOError as e:
print(e)
return tweets
if __name__ == "__main__":
parser = Twitter_Tools()
parser.json_parser()
我遇到一个错误:
Traceback (most recent call last): File ".\twitter_streamer.py", line 53, in <module>
parser.json_parser()
File ".\twitter_streamer.py", line 36, in json_parser
tweet = json.loads(line)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我很困惑,我的代码怎么了?
我的文本文件内容,大约是40mb的原始Twitter数据,例如:
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072108539904,"id_str":"1080583072108539904","text":"Trump pushes for border wall money as top lawmakers receive briefing https:\/\/t.co\/5wBjvy6Cfj via @YahooNews","source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":3259443492,"id_str":"3259443492","name":"Brian Wagner","screen_name":"brianwagner757","location":null,"url":null,"description":null,"translator_type":"none","protected":false,"verified":false,"followers_count":0,"friends_count":38,"listed_count":0,"favourites_count":1,"statuses_count":29,"created_at":"Mon Jun 29 03:21:03 +0000 2015","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5wBjvy6Cfj","expanded_url":"https:\/\/news.yahoo.com\/congress-reconvene-no-end-sight-federal-shutdown-060232512--business.html?soc_src=social-sh&soc_trk=tw","display_url":"news.yahoo.com\/congress-recon\u2026","indices":[69,92]}],"user_mentions":[{"screen_name":"YahooNews","name":"Yahoo News","id":7309052,"id_str":"7309052","indices":[97,107]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055310"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072427368448,"id_str":"1080583072427368448","text":"RT @MalcolmNance: I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea of wh\u2026","source":"\u003ca href=\"http:\/\/twitter.com\/#!\/download\/ipad\" rel=\"nofollow\"\u003eTwitter for iPad\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":799388189009948673,"id_str":"799388189009948673","name":"M L Bosin","screen_name":"LightLoveBliss2","location":"United States","url":"http:\/\/www.nsewi.org","description":"Speak truth-Harmony Seeker-Humanitarian Tweet my own opinions RT not endorsement of your content. Love is POWERFUL. Political Tweets when necessary","translator_type":"none","protected":false,"verified":false,"followers_count":1264,"friends_count":1265,"listed_count":1,"favourites_count":34425,"statuses_count":130623,"created_at":"Thu Nov 17 23:06:11 +0000 2016","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"91D2FA","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1071410517648928768\/ld0x54V8_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1071410517648928768\/ld0x54V8_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/799388189009948673\/1544279218","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Jan 02 19:08:23 +0000 2019","id":1080541330693152770,"id_str":"1080541330693152770","text":"I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea\u2026 https:\/\/t.co\/WD4VOmk8ps","display_text_range":[0,140],"source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":true,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2573480784,"id_str":"2573480784","name":"Malcolm Nance","screen_name":"MalcolmNance","location":null,"url":"http:\/\/www.thetacticsofterror.org","description":"US Intelligence +36 yrs. Expert Terrorist Strategy,Tactics,Ideology. Torture, Russian Cyber! | NYT Bestselling Author, Navy Senior Chief\/Jedi Master, NBC\/MSNBC.","translator_type":"none","protected":false,"verified":true,"followers_count":529620,"friends_count":1717,"listed_count":4390,"favourites_count":49486,"statuses_count":109601,"created_at":"Tue Jun 17 20:09:43 +0000 2014","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"131516","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":true,"profile_link_color":"009999","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/923550053289136128\/PLTG_LAf_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/923550053289136128\/PLTG_LAf_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2573480784\/1478903604","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"quoted_status_id":1080539235923517445,"quoted_status_id_str":"1080539235923517445","quoted_status":{"created_at":"Wed Jan 02 19:00:03 +0000 2019","id":1080539235923517445,"id_str":"1080539235923517445","text":"Live now on @MSNBC, https:\/\/t.co\/ZLcVcowcVM","display_text_range":[0,19],"source":"\u003ca href=\"https:\/\/about.twitter.com\/products\/tweetdeck\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2836421,"id_str":"2836421","name":"MSNBC","screen_name":"MSNBC","location":null,"url":"http:\/\/msnbc.com","description":"The place for in-depth analysis, political commentary and informed perspectives.","translator_type":"regular","protected":false,"verified":true,"followers_count":2285613,"friends_count":587,"listed_count":21993,"favourites_count":654,"statuses_count":152232,"created_at":"Thu Mar 29 13:15:41 +0000 2007","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0CB1C7","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EEEEEE","profile_text_color":"000000","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2836421\/1545246734","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":44,"reply_count":382,"retweet_count":38,"favorite_count":79,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MSNBC","name":"MSNBC","id":2836421,"id_str":"2836421","indices":[12,18]}],"symbols":[],"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"extended_entities":{"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_permalink":{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display":"twitter.com\/msnbc\/status\/1\u2026"},"is_quote_status":true,"extended_tweet":{"full_text":"I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea of what he is taking about. #Winning? https:\/\/t.co\/z7hXAyJqkU","display_text_range":[0,153],"entities":{"hashtags":[{"text":"Winning","indices":[144,152]}],"urls":[{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded_url":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display_url":"twitter.com\/msnbc\/status\/1\u2026","indices":[154,177]}],"user_mentions":[],"symbols":[]}},"quote_count":270,"reply_count":1298,"retweet_count":2804,"favorite_count":9853,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/WD4VOmk8ps","expanded_url":"https:\/\/twitter.com\/i\/web\/status\/1080541330693152770","display_url":"twitter.com\/i\/web\/status\/1\u2026","indices":[117,140]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_id":1080539235923517445,"quoted_status_id_str":"1080539235923517445","quoted_status":{"created_at":"Wed Jan 02 19:00:03 +0000 2019","id":1080539235923517445,"id_str":"1080539235923517445","text":"Live now on @MSNBC, https:\/\/t.co\/ZLcVcowcVM","display_text_range":[0,19],"source":"\u003ca href=\"https:\/\/about.twitter.com\/products\/tweetdeck\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2836421,"id_str":"2836421","name":"MSNBC","screen_name":"MSNBC","location":null,"url":"http:\/\/msnbc.com","description":"The place for in-depth analysis, political commentary and informed perspectives.","translator_type":"regular","protected":false,"verified":true,"followers_count":2285613,"friends_count":587,"listed_count":21993,"favourites_count":654,"statuses_count":152232,"created_at":"Thu Mar 29 13:15:41 +0000 2007","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0CB1C7","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EEEEEE","profile_text_color":"000000","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2836421\/1545246734","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":44,"reply_count":382,"retweet_count":38,"favorite_count":79,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MSNBC","name":"MSNBC","id":2836421,"id_str":"2836421","indices":[12,18]}],"symbols":[],"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"extended_entities":{"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_permalink":{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display":"twitter.com\/msnbc\/status\/1\u2026"},"is_quote_status":true,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MalcolmNance","name":"Malcolm Nance","id":2573480784,"id_str":"2573480784","indices":[3,16]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055386"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072355995648,"id_str":"1080583072355995648","text":"Kellyanne's husband torches Trump on Twitter. Again https:\/\/t.co\/yQiSJgC6Kr","source":"\u003ca href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\"\u003eTwitter for Android\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":903413191,"id_str":"903413191","name":"Veronika Fimbres","screen_name":"vcdiva_vf","location":"San Francisco, California","url":"http:\/\/veronikafimbres.com","description":"http:\/\/www.gp.org\/fimbres_compassionate_candidate","translator_type":"none","protected":false,"verified":false,"followers_count":245,"friends_count":671,"listed_count":11,"favourites_count":3104,"statuses_count":7666,"created_at":"Thu Oct 25 07:25:53 +0000 2012","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/2808280665\/2d02f3abbfd0639a2ec4a4ea6fd968dd_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/2808280665\/2d02f3abbfd0639a2ec4a4ea6fd968dd_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/903413191\/1360173815","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/yQiSJgC6Kr","expanded_url":"https:\/\/www.dailykos.com\/story\/2019\/1\/1\/1822909\/-Kellyanne-s-husband-torches-Trump-on-Twitter-Again","display_url":"dailykos.com\/story\/2019\/1\/1\u2026","indices":[52,75]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055369"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072603607045,"id_str":"1080583072603607045","text":"RT @sirDukeDevin: President Trump: \"I think I would have been a good general, but who knows?\"\n\nYou would need integrity for that @realDonal\u2026","source":"\u003ca href=\"https:\/\/mobile.twitter.com\" rel=\"nofollow\"\u003eTwitter Lite\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":42693452,"id_str":"42693452","name":"Wine Lover","screen_name":"wineandjazz72","location":"New York","url":null,"description":"S.F. \/ Oakland Bay Area Lady living in NYC.","translator_type":"none","protected":false,"verified":false,"followers_count":939,"friends_count":611,"listed_count":13,"favourites_count":27733,"statuses_count":20022,"created_at":"Tue May 26 19:06:47 +0000 2009","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"EDECE9","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_tile":false,"profile_link_color":"088253","profile_sidebar_border_color":"D3D2CF","profile_sidebar_fill_color":"E3E2DE","profile_text_color":"634047","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/822965713489031168\/A2FEStLn_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/822965713489031168\/A2FEStLn_normal.jpg","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Jan 02 19:53:23 +0000 2019","id":1080552657058754560,"id_str":"1080552657058754560","text":"President Trump: \"I think I would have been a good general, but who knows?\"\n\nYou would need integrity for that @realDonaldTrump.","source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":838351435595149312,"id_str":"838351435595149312","name":"Devin Duke","screen_name":"sirDukeDevin","location":null,"url":null,"description":"Dad, skeptic, formerly a cognitive neuroscientist. Centrist who fully supports our vets, military brat. #BlockedbyTrump #BlockedbyHannity","translator_type":"none","protected":false,"verified":false,"followers_count":66490,"friends_count":60098,"listed_count":178,"favourites_count":9889,"statuses_count":6682,"created_at":"Sun Mar 05 11:32:12 +0000 2017","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"F5F8FA","profile_background_image_url":"","profile_background_image_url_https":"","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1063972328089010176\/xejYOXNd_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1063972328089010176\/xejYOXNd_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/838351435595149312\/1489426530","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":67,"reply_count":349,"retweet_count":402,"favorite_count":2062,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"realDonaldTrump","name":"Donald J. Trump","id":25073877,"id_str":"25073877","indices":[111,127]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en"},"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"sirDukeDevin","name":"Devin Duke","id":838351435595149312,"id_str":"838351435595149312","indices":[3,16]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055428"}
答案 0 :(得分:1)
检查数据中是否有空行...您发现其中有空行(也许最后一行的末尾有\ n?),结果为raise JSONDecodeError("Expecting value", s, err.value) from None
。
这可以修复该错误:
import os
import json
class Twitter_Tools():
def json_parser(filename):
filename = '\\twitter_data_2.txt' # changed name to avoid overwriting yours
cpath = os.getcwd()
realfilename = cpath + filename
print(realfilename)
tweets = []
if(realfilename != None):
try:
with open(realfilename, "r") as reader:
for line in reader:
if line.strip(): # fix problem: do not parse empty lines
tweet = json.loads(line)
tweets.append(tweet)
except IOError as e:
print(e)
return tweets
if __name__ == "__main__":
# create a file with a newline after last line to recreate problem
with open("twitter_data_2.txt","w") as f:
f.write( """{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072108539904,"id_str":"1080583072108539904","text":"Trump pushes for border wall money as top lawmakers receive briefing https:\/\/t.co\/5wBjvy6Cfj via @YahooNews","source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":
{"id":3259443492,"id_str":"3259443492","name":"Brian Wagner","screen_name":"brianwagner757","location":null,"url":null,"description":null,"translator_type":"none","protected":false,"verified":false,"followers_count":0,"friends_count":38,"listed_count":0,"favourites_count":1,"statuses_count":29,"created_at":"Mon Jun 29 03:21:03 +0000 2015","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5wBjvy6Cfj","expanded_url":"https:\/\/news.yahoo.com\/congress-reconvene-no-end-sight-federal-shutdown-060232512--business.html?soc_src=social-sh&soc_trk=tw","display_url":"news.yahoo.com\/congress-recon\u2026","indices":[69,92]}],"user_mentions":[{"screen_name":"YahooNews","name":"Yahoo News","id":7309052,"id_str":"7309052","indices":[97,107]}],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055310"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072427368448,"id_str":"1080583072427368448","text":"RT @MalcolmNance: I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea of wh\u2026","source":"\u003ca href=\"http:\/\/twitter.com\/#!\/download\/ipad\" rel=\"nofollow\"\u003eTwitter for iPad\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":799388189009948673,"id_str":"799388189009948673","name":"M L Bosin","screen_name":"LightLoveBliss2","location":"United States","url":"http:\/\/www.nsewi.org","description":"Speak truth-Harmony Seeker-Humanitarian Tweet my own opinions RT not endorsement of your content. Love is POWERFUL. Political Tweets when necessary","translator_type":"none","protected":false,"verified":false,"followers_count":1264,"friends_count":1265,"listed_count":1,"favourites_count":34425,"statuses_count":130623,"created_at":"Thu Nov 17 23:06:11 +0000 2016","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"91D2FA","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1071410517648928768\/ld0x54V8_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1071410517648928768\/ld0x54V8_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/799388189009948673\/1544279218","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":
{"created_at":"Wed Jan 02 19:08:23 +0000 2019","id":1080541330693152770,"id_str":"1080541330693152770","text":"I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea\u2026 https:\/\/t.co\/WD4VOmk8ps","display_text_range":[0,140],"source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":true,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user": {"id":2573480784,"id_str":"2573480784","name":"Malcolm Nance","screen_name":"MalcolmNance","location":null,"url":"http:\/\/www.thetacticsofterror.org","description":"US Intelligence +36 yrs. Expert Terrorist Strategy,Tactics,Ideology. Torture, Russian Cyber! | NYT Bestselling Author, Navy Senior Chief\/Jedi Master, NBC\/MSNBC.","translator_type":"none","protected":false,"verified":true,"followers_count":529620,"friends_count":1717,"listed_count":4390,"favourites_count":49486,"statuses_count":109601,"created_at":"Tue Jun 17 20:09:43 +0000 2014","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"131516","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":true,"profile_link_color":"009999","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/923550053289136128\/PLTG_LAf_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/923550053289136128\/PLTG_LAf_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2573480784\/1478903604","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"quoted_status_id":1080539235923517445,"quoted_status_id_str":"1080539235923517445","quoted_status":{"created_at":"Wed Jan 02 19:00:03 +0000 2019","id":1080539235923517445,"id_str":"1080539235923517445","text":"Live now on @MSNBC, https:\/\/t.co\/ZLcVcowcVM","display_text_range":[0,19],"source":"\u003ca href=\"https:\/\/about.twitter.com\/products\/tweetdeck\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2836421,"id_str":"2836421","name":"MSNBC","screen_name":"MSNBC","location":null,"url":"http:\/\/msnbc.com","description":"The place for in-depth analysis, political commentary and informed perspectives.","translator_type":"regular","protected":false,"verified":true,"followers_count":2285613,"friends_count":587,"listed_count":21993,"favourites_count":654,"statuses_count":152232,"created_at":"Thu Mar 29 13:15:41 +0000 2007","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0CB1C7","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EEEEEE","profile_text_color":"000000","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2836421\/1545246734","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":44,"reply_count":382,"retweet_count":38,"favorite_count":79,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MSNBC","name":"MSNBC","id":2836421,"id_str":"2836421","indices":[12,18]}],"symbols":[],"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"extended_entities":{"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_permalink":{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display":"twitter.com\/msnbc\/status\/1\u2026"},"is_quote_status":true,"extended_tweet":{"full_text":"I\u2019m listening to this \u201ccabinet meeting\u201d and you can be sure Trump is an absolute idiot. He babbles without any idea of what he is taking about. #Winning? https:\/\/t.co\/z7hXAyJqkU","display_text_range":[0,153],"entities":{"hashtags":[{"text":"Winning","indices":[144,152]}],"urls":[{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded_url":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display_url":"twitter.com\/msnbc\/status\/1\u2026","indices":[154,177]}],"user_mentions":[],"symbols":[]}},"quote_count":270,"reply_count":1298,"retweet_count":2804,"favorite_count":9853,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/WD4VOmk8ps","expanded_url":"https:\/\/twitter.com\/i\/web\/status\/1080541330693152770","display_url":"twitter.com\/i\/web\/status\/1\u2026","indices":[117,140]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_id":1080539235923517445,"quoted_status_id_str":"1080539235923517445","quoted_status":{"created_at":"Wed Jan 02 19:00:03 +0000 2019","id":1080539235923517445,"id_str":"1080539235923517445","text":"Live now on @MSNBC, https:\/\/t.co\/ZLcVcowcVM","display_text_range":[0,19],"source":"\u003ca href=\"https:\/\/about.twitter.com\/products\/tweetdeck\" rel=\"nofollow\"\u003eTweetDeck\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2836421,"id_str":"2836421","name":"MSNBC","screen_name":"MSNBC","location":null,"url":"http:\/\/msnbc.com","description":"The place for in-depth analysis, political commentary and informed perspectives.","translator_type":"regular","protected":false,"verified":true,"followers_count":2285613,"friends_count":587,"listed_count":21993,"favourites_count":654,"statuses_count":152232,"created_at":"Thu Mar 29 13:15:41 +0000 2007","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0CB1C7","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"EEEEEE","profile_text_color":"000000","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/988382060443250689\/DijesdNB_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2836421\/1545246734","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":44,"reply_count":382,"retweet_count":38,"favorite_count":79,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MSNBC","name":"MSNBC","id":2836421,"id_str":"2836421","indices":[12,18]}],"symbols":[],"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"extended_entities":{"media":[{"id":1080539215287500801,"id_str":"1080539215287500801","indices":[20,43],"media_url":"http:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/Dv7YsP0XQAEnQX-.jpg","url":"https:\/\/t.co\/ZLcVcowcVM","display_url":"pic.twitter.com\/ZLcVcowcVM","expanded_url":"https:\/\/twitter.com\/MSNBC\/status\/1080539235923517445\/photo\/1","type":"photo","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":1200,"h":675,"resize":"fit"},"small":{"w":680,"h":383,"resize":"fit"},"large":{"w":1920,"h":1080,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"quoted_status_permalink":{"url":"https:\/\/t.co\/z7hXAyJqkU","expanded":"https:\/\/twitter.com\/msnbc\/status\/1080539235923517445","display":"twitter.com\/msnbc\/status\/1\u2026"},"is_quote_status":true,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"MalcolmNance","name":"Malcolm Nance","id":2573480784,"id_str":"2573480784","indices":[3,16]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055386"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072355995648,"id_str":"1080583072355995648","text":"Kellyanne's husband torches Trump on Twitter. Again https:\/\/t.co\/yQiSJgC6Kr","source":"\u003ca href=\"http:\/\/twitter.com\/download\/android\" rel=\"nofollow\"\u003eTwitter for Android\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":903413191,"id_str":"903413191","name":"Veronika Fimbres","screen_name":"vcdiva_vf","location":"San Francisco, California","url":"http:\/\/veronikafimbres.com","description":"http:\/\/www.gp.org\/fimbres_compassionate_candidate","translator_type":"none","protected":false,"verified":false,"followers_count":245,"friends_count":671,"listed_count":11,"favourites_count":3104,"statuses_count":7666,"created_at":"Thu Oct 25 07:25:53 +0000 2012","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/2808280665\/2d02f3abbfd0639a2ec4a4ea6fd968dd_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/2808280665\/2d02f3abbfd0639a2ec4a4ea6fd968dd_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/903413191\/1360173815","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/yQiSJgC6Kr","expanded_url":"https:\/\/www.dailykos.com\/story\/2019\/1\/1\/1822909\/-Kellyanne-s-husband-torches-Trump-on-Twitter-Again","display_url":"dailykos.com\/story\/2019\/1\/1\u2026","indices":[52,75]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055369"}
{"created_at":"Wed Jan 02 21:54:15 +0000 2019","id":1080583072603607045,"id_str":"1080583072603607045","text":"RT @sirDukeDevin: President Trump: \"I think I would have been a good general, but who knows?\"\n\nYou would need integrity for that @realDonal\u2026","source":"\u003ca href=\"https:\/\/mobile.twitter.com\" rel=\"nofollow\"\u003eTwitter Lite\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":42693452,"id_str":"42693452","name":"Wine Lover","screen_name":"wineandjazz72","location":"New York","url":null,"description":"S.F. \/ Oakland Bay Area Lady living in NYC.","translator_type":"none","protected":false,"verified":false,"followers_count":939,"friends_count":611,"listed_count":13,"favourites_count":27733,"statuses_count":20022,"created_at":"Tue May 26 19:06:47 +0000 2009","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"EDECE9","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_tile":false,"profile_link_color":"088253","profile_sidebar_border_color":"D3D2CF","profile_sidebar_fill_color":"E3E2DE","profile_text_color":"634047","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/822965713489031168\/A2FEStLn_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/822965713489031168\/A2FEStLn_normal.jpg","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Wed Jan 02 19:53:23 +0000 2019","id":1080552657058754560,"id_str":"1080552657058754560","text":"President Trump: \"I think I would have been a good general, but who knows?\"\n\nYou would need integrity for that @realDonaldTrump.","source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":838351435595149312,"id_str":"838351435595149312","name":"Devin Duke","screen_name":"sirDukeDevin","location":null,"url":null,"description":"Dad, skeptic, formerly a cognitive neuroscientist. Centrist who fully supports our vets, military brat. #BlockedbyTrump #BlockedbyHannity","translator_type":"none","protected":false,"verified":false,"followers_count":66490,"friends_count":60098,"listed_count":178,"favourites_count":9889,"statuses_count":6682,"created_at":"Sun Mar 05 11:32:12 +0000 2017","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"F5F8FA","profile_background_image_url":"","profile_background_image_url_https":"","profile_background_tile":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1063972328089010176\/xejYOXNd_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1063972328089010176\/xejYOXNd_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/838351435595149312\/1489426530","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":67,"reply_count":349,"retweet_count":402,"favorite_count":2062,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"realDonaldTrump","name":"Donald J. Trump","id":25073877,"id_str":"25073877","indices":[111,127]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en"},"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"sirDukeDevin","name":"Devin Duke","id":838351435595149312,"id_str":"838351435595149312","indices":[3,16]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1546466055428"}
""")
parser = Twitter_Tools()
parser.json_parser()
更新的文件内容会导致另一个错误:
Message=Expecting ',' delimiter: line 1 column 243 (char 242)
您的json格式不正确。修复原始数据。