在Python 3.4

时间:2017-08-07 10:55:08

标签: python json twitter

我是python的初学者,我需要一些帮助才能读取一些有一些推文作为数据的json文件。

我已将这些数据保存在json文件中,当我尝试读取该文件时。我有一些错误:

ValueError: Expecting value: line 2 column 1 (char 1)

有人能帮助我吗?

我的json文件内容是: {" created_at":" Mon Aug 07 08:38:17 +0000 2017"," id":894477786047553536," id_str":& #34; 894477786047553536","文字":" @KevinRobMartin @PSTeamOnline @PokerStars现代5-7-9扑克牌。 Holadeck:\ nAHD规则:All Hands on Deck - 所有\ u2026 https://t.co/gOzpJgwcgX" ;," display_text_range":[42,140]," source": " \ u003ca href = \" http://twitter.com \" rel = \" nofollow \" \ u003eTwitter Web Client \ u003c / a \ u003e","截断":true," in_reply_to_status_id":894310275763113985,& #34; in_reply_to_status_id_str":" 894310275763113985"" in_reply_to_user_id":2483027940," in_reply_to_user_id_str":" 2483027940"" in_reply_to_screen_name":" KevinRobMartin""使用者" {" ID":812269114551136256" ID_STR":" 812269114551136256&# 34;,"名称":" Chesmayne"" SCREEN_NAME":" Chesmayne2017""位置":&# 34; Dublin Dublin Europe Gaia"," url":" http://homepage.eircom.net/~reidr1/index.html"," description&# 34;:" Leanne Jordan。游戏Web图形打印设计师CEO&社交媒体:CHESS,POKER,Astronomy。通过G-mail与我联系:chesmayne2014@gmail.com"," protected":false,"已验证":false," followers_count":251,& #34; FRIENDS_COUNT":423," listed_count":9," favourites_count":1030," statuses_count":3597," created_at&#34 ;:" Fri Dec 23 12:10:22 +0000 2016"," utc_offset":null," time_zone":null," geo_enabled&#34 ;:真,"朗":"恩"" contributors_enabled":假," is_translator":假," profile_background_color&# 34;:" 000000"" profile_background_image_url":" HTTP://abs.twimg.com/images/themes/theme1/bg.png",&# 34; profile_background_image_url_https":" HTTPS://abs.twimg.com/images/themes/theme1/bg.png"," profile_background_tile":假,"&profile_link_color #34;:" 981CEB"" profile_sidebar_border_color":" 000000"" profile_sidebar_fill_color":" 000000",& #34; profile_text_color":" 000000"" profile_use_back ground_image":假," profile_image_url":" HTTP://pbs.twimg.com/profile_images/873654899220860929/Gh1zCGk4_normal.jpg"," profile_image_url_https&#34 ;: " HTTPS://pbs.twimg.com/profile_images/873654899220860929/Gh1zCGk4_normal.jpg"," profile_banner_url":" HTTPS://pbs.twimg.com/profile_banners/ 1497130468分之812269114551136256"" DEFAULT_PROFILE":假," default_profile_image":假,"以下":空," follow_request_sent":空"通知":空}"地理":空,"坐标":空,"地方" {" ID& #34;:" 7dde0febc9ef245b"" URL":" HTTPS://api.twitter.com/1.1/geo/id/7dde0febc9ef245b.json",& #34; place_type":" city"," name":" Dublin City"," full_name":" Dublin爱尔兰城市"," country_code":" IE","国家":"爱尔兰"," bounding_box&#34 ;:{"类型":"多边形""坐标":[[[ - 6.387438,53.2 98745],[ - 6.387438,53.411060],[ - 6.107805,53.411060],[ - 6.107805,53.298745]]]},"属性":{}},"贡献者":空," is_quote_status":false," extended_tweet":{" full_text":" @KevinRobMartin @PSTeamOnline @PokerStars Modern 5-7-9扑克牌。 Holadeck:\ nAHD规则:所有动手在甲板上 - 所有人都允许\ n最新:https://t.co/FDxM8RoITY https://t.co/Rx0Kiu3FRN" ;," display_text_range":[ 42161]"实体" {"#标签":[],"网址":[{" URL":" HTTPS ://t.co/FDxM8RoITY"," expanded_url":" HTTPS://www.facebook.com/ches.mayne.9"," DISPLAY_URL&# 34;:" facebook.com/ches.mayne.9","指数":[138161]}]," user_mentions":[{" screen_name":" KevinRobMartin"," name":" Kevin Martin"," id":2483027940," id_str&# 34;:" 2483027940""指数":[0,15]},{" SCREEN_NAME":" PSTeamOnline"&#34 ;姓名":" Team Pro Online"," id":245412615," id_str":" 245412615","指数":[16,29]},{" SCREEN_NAME":"扑克""名称":"扑克",& #34; ID":19537263," ID_STR":" 19537263""指数":[30,41]}],"符号& #34;:[],"媒体":[{" ID":894477755517218818" ID_STR":" 894477755517218818""指数":[162185],& #34; MEDIA_URL":" HTTP://pbs.twimg.com/media/DGnSx40XsAIUwF_.jpg"," media_url_https":" https://开头PBS。 twimg.com/media/DGnSx40XsAIUwF_.jpg","url":"https://t.co/Rx0Kiu3FRN","display_url":&# 34; pic.twitter.com/Rx0Kiu3FRN"," expanded_url":" HTTPS://twitter.com/Chesmayne2017/status/894477786047553536/photo/1",&#34 ;类型":"相片""尺寸" {"介质" {" W" 960" H":640,"调整":"适合"}"拇指" {" W":150,&#34 ; H":150,"调整":"作物"}"大" {" W" 960&# 34; H":640,"调整":"适合"}"小" {" W":680,& #34; H" 453"调整":"适合"}}},{" ID":894477778439024643" ID_STR&#34 ;:" 894477778439024643""指数&#34 ;: [162185]," MEDIA_URL":" HTTP:// PB s.twimg.com/media/DGnSzONWsAMaj2_.jpg","media_url_https":"https://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg"," ; URL":" HTTPS://t.co/Rx0Kiu3FRN"," DISPLAY_URL":" pic.twitter.com/Rx0Kiu3FRN",&#34 ; expanded_url":" HTTPS://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","类型":"相片",& #34;尺寸" {"介质" {" W" 960" H":640,"调整&#34 ;: "适合"}"拇指" {" W":150," H":150,"调整" :"作物"}"大" {" W" 960" H":640,"调整&#34 ;:"适合"}"小" {" W" 680" H" 453"调整&# 34;:"适合"}}}]}," extended_entities" {"介质":[{" ID":894477755517218818,& #34; ID_STR":" 894477755517218818""指数&#34 ;: [162185]," MEDIA_URL":" HTTP://pbs.twimg的.com /媒体/ DGnSx40XsAIUwF_.jpg"" media_url_https":" HTTPS://pbs.twimg.com/medi一个/ DGnSx40XsAIUwF_.jpg"" URL":" HTTPS://t.co/Rx0Kiu3FRN"," DISPLAY_URL":" PIC。 twitter.com/Rx0Kiu3FRN","expanded_url":"https://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","type" ;:"相片""尺寸" {"介质" {" W" 960" H" :640,"调整":"适合"}"拇指" {" W":150," H&#34 ;:150,"调整":"作物"}"大" {" W" 960" H&# 34;:640,"调整":"适合"}"小" {" W" 680" H& #34; 453"调整":"适合"}}},{" ID":894477778439024643" ID_STR":&# 34; 894477778439024643""指数&#34 ;: [162185]," MEDIA_URL":" HTTP://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg" ;," media_url_https":" HTTPS://pbs.twimg.com/media/DGnSzONWsAMaj2_.jpg"," URL":" HTTPS:/ /t.co/Rx0Kiu3FRN","display_url":"pic.twitter.com/Rx0Kiu3FRN","expanded_网址":" HTTPS://twitter.com/Chesmayne2017/status/894477786047553536/photo/1","类型":"相片"&# 34;尺寸" {"介质" {" W" 960" H":640,"调整":& #34;适合"}"拇指" {" W":150," H":150,"调整&#34 ;: "作物"}"大" {" W" 960" H":640,"调整" :"适合"}"小" {" W" 680" H" 453"调整&#34 ;:"适合"}}}]}}" retweet_count":0," FAVORITE_COUNT":0,"实体":{& #34;#标签&#34 ;: [],"网址&#34 ;: [{" URL":" HTTPS://t.co/gOzpJgwcgX",&# 34; expanded_url":" HTTPS://twitter.com/i/web/status/894477786047553536"," DISPLAY_URL":" twitter.com/i/web /状态/ 8 \ U2026""指数":[117140]}]," user_mentions":[{" SCREEN_NAME":" KevinRobMartin& #34;,"姓名":" Kevin Martin"," id":2483027940," id_str":" 2483027940&#34 ;,"指数":[0, 15]},{" screen_name":" PSTeamOnline"," name":" Team Pro Online"," id&#34 ;:245412615" ID_STR":" 245412615""指数":[16,29]},{" SCREEN_NAME":&# 34;扑克""名称":"扑克"" ID":19537263," ID_STR":" 19537263& #34;"指数":[30,41]}],"符号":[]},"收藏":假,"转推& #34;:假," possibly_sensitive":假," filter_level":"低""朗":"恩&# 34;," TIMESTAMP_MS":" 1502095097444"}

filename = 'publictweets.json' 
with open(filename, 'r') as f: 
    count_all = Counter() 
    for line in f: 
        tweet = json.loads(line)

1 个答案:

答案 0 :(得分:0)

我已经能够解决问题并感谢您的帮助。

   filename = 'publictweets.json'
   with open(filename, 'r') as f:
        for line in f:
            if line.strip():
               tweet = json.loads(line)