简体   繁体   English

尝试使用 python 解析 JSON 时出现“TypeError: expected string or buffer”

[英]"TypeError: expected string or buffer" when attempting to parse JSON using python

I am new to Python & Json processing.我是 Python 和 Json 处理的新手。 I am using Python 2.7.我正在使用 Python 2.7。 I get several error messages When i execute the following code:当我执行以下代码时,我收到几条错误消息:

import os
import ast
import json

tweets={}
with open('C:\Python27\Test data\json\companies1.json','r') as input_file:
     tweets = json.loads(input_file)
     print  tweets.keys()
     print "\n"

Error message is below:错误信息如下:

 Traceback (most recent call last):
 File "C:/Users/afurxr3/PycharmProjects/Coudera/LargeJSON.py", line 13, in <module>
 tweets = json.loads(input_file)
 File "C:\Python27\lib\json\__init__.py", line 339, in loads
 return _default_decoder.decode(s)
 File "C:\Python27\lib\json\decoder.py", line 364, in decode
 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
 TypeError: expected string or buffer

 Process finished with exit code 1

I don't get any errors when i execute the following code but some of intial Json keys are missing:执行以下代码时没有出现任何错误,但缺少一些初始 Json 键:

  import os
  import ast
  import json

 tweets=[]
 for line in open('C:\Python27\Test data\json\companies1.json','r'):
       tweets.append(json.loads(line))
       print (json.dumps(tweets,indent=4))
       print "\n"

My Json input file is below:我的 Json 输入文件如下:

{ "_id" : { "$oid" : "52cdef7c4bab8bd675297d8a" }, "name" : "Wetpaint", "permalink" : "abc2", "crunchbase_url" : "http://www.crunchbase.com/company/wetpaint", "homepage_url" : "http://wetpaint-inc.com", "blog_url" : "http://digitalquarters.net/", "blog_feed_url" : "http://digitalquarters.net/feed/", "twitter_username" : "BachelrWetpaint", "category_code" : "web", "number_of_employees" : 47, "founded_year" : 2005, "founded_month" : 10, "founded_day" : 17, "deadpooled_year" : 1, "tag_list" : "wiki, seattle, elowitz, media-industry, media-platform, social-distribution-system", "alias_list" : "", "email_address" : "info@wetpaint.com", "phone_number" : "206.859.6300", "description" : "Technology Platform Company", "created_at" : { "$date" : 1180075887000 }, "updated_at" : "Sun Dec 08 07:15:44 UTC 2013", "overview" : "<p>Wetpaint is a technology platform company that uses its proprietary state-of-the-art technology and expertise in social media to build and monetize audiences for digital publishers. Wetpaint’s own online property, Wetpaint Entertainment, an entertainment news site that attracts more than 12 million unique visitors monthly and has over 2 million Facebook fans, is a proof point to the company’s success in building and engaging audiences. Media companies can license Wetpaint’s platform which includes a dynamic playbook tailored to their individual needs and comprehensive training. Founded by Internet pioneer Ben Elowitz, and with offices in New York and Seattle, Wetpaint is backed by Accel Partners, the investors behind Facebook.</p>", "image" : { "available_sizes" : [ [ [ 150, 75 ], "assets/images/resized/0000/3604/3604v14-max-150x150.jpg" ], [ [ 250, 125 ], "assets/images/resized/0000/3604/3604v14-max-250x250.jpg" ], [ [ 450, 225 ], "assets/images/resized/0000/3604/3604v14-max-450x450.jpg" ] ] }, "products" : [ { "name" : "Wikison Wetpaint", "permalink" : "wetpaint-wiki" }, { "name" : "Wetpaint Social Distribution System", "permalink" : "wetpaint-social-distribution-system" } ], "relationships" : [ { "is_past" : false, "title" : "Co-Founder and VP, Social and Audience Development", "person" : { "first_name" : "Michael", "last_name" : "Howell", "permalink" : "michael-howell" } }, { "is_past" : false, "title" : "Co-Founder/CEO/Board of Directors", "person" : { "first_name" : "Ben", "last_name" : "Elowitz", "permalink" : "ben-elowitz" } }, { "is_past" : false, "title" : "COO/Board of Directors", "person" : { "first_name" : "Rob", "last_name" : "Grady", "permalink" : "rob-grady" } }, { "is_past" : false, "title" : "SVP, Strategy and Business Development", "person" : { "first_name" : "Chris", "last_name" : "Kollas", "permalink" : "chris-kollas" } }, { "is_past" : false, "title" : "Board", "person" : { "first_name" : "Theresia", "last_name" : "Ranzetta", "permalink" : "theresia-ranzetta" } }, { "is_past" : false, "title" : "Board Member", "person" : { "first_name" : "Gus", "last_name" : "Tai", "permalink" : "gus-tai" } }, { "is_past" : false, "title" : "Board", "person" : { "first_name" : "Len", "last_name" : "Jordan", "permalink" : "len-jordan" } }, { "is_past" : false, "title" : "Head of Technology and Product", "person" : { "first_name" : "Alex", "last_name" : "Weinstein", "permalink" : "alex-weinstein" } }, { "is_past" : true, "title" : "CFO", "person" : { "first_name" : "Bert", "last_name" : "Hogue", "permalink" : "bert-hogue" } }, { "is_past" : true, "title" : "CFO/ CRO", "person" : { "first_name" : "Brian", "last_name" : "Watkins", "permalink" : "brian-watkins" } }, { "is_past" : true, "title" : "Senior Vice President, Marketing", "person" : { "first_name" : "Rob", "last_name" : "Grady", "permalink" : "rob-grady" } }, { "is_past" : true, "title" : "VP, Technology and Product", "person" : { "first_name" : "Werner", "last_name" : "Koepf", "permalink" : "werner-koepf" } }, { "is_past" : true, "title" : "VP Marketing", "person" : { "first_name" : "Kevin", "last_name" : "Flaherty", "permalink" : "kevin-flaherty" } }, { "is_past" : true, "title" : "VP User Experience", "person" : { "first_name" : "Alex", "last_name" : "Berg", "permalink" : "alex-berg" } }, { "is_past" : true, "title" : "VP Engineering", "person" : { "first_name" : "Steve", "last_name" : "McQuade", "permalink" : "steve-mcquade" } }, { "is_past" : true, "title" : "Executive Editor", "person" : { "first_name" : "Susan", "last_name" : "Mulcahy", "permalink" : "susan-mulcahy" } }, { "is_past" : true, "title" : "VP Business Development", "person" : { "first_name" : "Chris", "last_name" : "Kollas", "permalink" : "chris-kollas" } } ], "competitions" : [ { "competitor" : { "name" : "Wikia", "permalink" : "wikia" } }, { "competitor" : { "name" : "JotSpot", "permalink" : "jotspot" } }, { "competitor" : { "name" : "Socialtext", "permalink" : "socialtext" } }, { "competitor" : { "name" : "Ning by Glam Media", "permalink" : "ning" } }, { "competitor" : { "name" : "Soceeo", "permalink" : "soceeo" } }, { "competitor" : { "name" : "Yola", "permalink" : "yola" } }, { "competitor" : { "name" : "SocialGO", "permalink" : "socialgo" } }, { "competitor" : { "name" : "IslamNor", "permalink" : "islamnor" } } ], "providerships" : [], "total_money_raised" : "$39.8M", "funding_rounds" : [ { "id" : 888, "round_code" : "a", "source_url" : "http://seattlepi.nwsource.com/business/246734_wiki02.html", "source_description" : "", "raised_amount" : 5250000, "raised_currency_code" : "USD", "funded_year" : 2005, "funded_month" : 10, "funded_day" : 1, "investments" : [ { "company" : null, "financial_org" : { "name" : "Frazier Technology Ventures", "permalink" : "frazier-technology-ventures" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Trinity Ventures", "permalink" : "trinity-ventures" }, "person" : null } ] }, { "id" : 889, "round_code" : "b", "source_url" : "http://pulse2.com/2007/01/09/wiki-builder-website-wetpaint-welcomes-95m-funding/", "source_description" : "", "raised_amount" : 9500000, "raised_currency_code" : "USD", "funded_year" : 2007, "funded_month" : 1, "funded_day" : 1, "investments" : [ { "company" : null, "financial_org" : { "name" : "Accel Partners", "permalink" : "accel-partners" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Frazier Technology Ventures", "permalink" : "frazier-technology-ventures" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Trinity Ventures", "permalink" : "trinity-ventures" }, "person" : null } ] }, { "id" : 2312, "round_code" : "c", "source_url" : "http://www.accel.com/news/news_one_up.php?news_id=185", "source_description" : "Accel", "raised_amount" : 25000000, "raised_currency_code" : "USD", "funded_year" : 2008, "funded_month" : 5, "funded_day" : 19, "investments" : [ { "company" : null, "financial_org" : { "name" : "DAG Ventures", "permalink" : "dag-ventures" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Accel Partners", "permalink" : "accel-partners" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Trinity Ventures", "permalink" : "trinity-ventures" }, "person" : null }, { "company" : null, "financial_org" : { "name" : "Frazier Technology Ventures", "permalink" : "frazier-technology-ventures" }, "person" : null } ] } ], "investments" : [], "acquisition" : { "price_amount" : 30000000, "price_currency_code" : "USD", "term_code" : "cash_and_stock", "source_url" : "http://allthingsd.com/20131216/viggle-tries-to-bulk-up-its-social-tv-business-by-buying-wetpaint/?mod=atdtweet", "source_description" : " Viggle Tries to Bulk Up Its Social TV Business by Buying Wetpaint", "acquired_year" : 2013, "acquired_month" : 12, "acquired_day" : 16, "acquiring_company" : { "name" : "Viggle", "permalink" : "viggle" } }, "acquisitions" : [], "offices" : [ { "description" : "", "address1" : "710 - 2nd Avenue", "address2" : "Suite 1100", "zip_code" : "98104", "city" : "Seattle", "state_code" : "WA", "country_code" : "USA", "latitude" : 47.603122, "longitude" : -122.333253 }, { "description" : "", "address1" : "270 Lafayette Street", "address2" : "Suite 505", "zip_code" : "10012", "city" : "New York", "state_code" : "NY", "country_code" : "USA", "latitude" : 40.7237306, "longitude" : -73.9964312 } ], "milestones" : [ { "id" : 5869, "description" : "Wetpaint named in Lead411's Hottest Seattle Companies list", "stoned_year" : 2010, "stoned_month" : 6, "stoned_day" : 8, "source_url" : "http://www.lead411.com/seattle-companies.html", "source_text" : null, "source_description" : "LEAD411 LAUNCHES \"HOTTEST SEATTLE COMPANIES\" AWARDS", "stoneable_type" : "Company", "stoned_value" : null, "stoned_value_type" : null, "stoned_acquirer" : null, "stoneable" : { "name" : "Wetpaint", "permalink" : "wetpaint" } }, { "id" : 8702, "description" : "Site-Builder Wetpaint Makes One For Itself, Using the Demand Media Playbook", "stoned_year" : 2010, "stoned_month" : 9, "stoned_day" : 6, "source_url" : "http://mediamemo.allthingsd.com/20100906/site-builder-wetpaint-makes-one-for-itself-using-the-demand-media-playbook/", "source_text" : null, "source_description" : "All Things D", "stoneable_type" : "Company", "stoned_value" : null, "stoned_value_type" : null, "stoned_acquirer" : null, "stoneable" : { "name" : "Wetpaint", "permalink" : "wetpaint" } } ], "video_embeds" : [], "screenshots" : [ { "available_sizes" : [ [ [ 150, 86 ], "assets/images/resized/0016/0929/160929v2-max-150x150.png" ], [ [ 250, 143 ], "assets/images/resized/0016/0929/160929v2-max-250x250.png" ], [ [ 450, 258 ], "assets/images/resized/0016/0929/160929v2-max-450x450.png" ] ], "attribution" : null } ], "external_links" : [ { "external_url" : "http://www.geekwire.com/2011/rewind-ben-elowitz-wetpaint-ceo-building-type-media-company", "title" : "GeekWire interview: Rewind - Ben Elowitz, Wetpaint CEO, on building a new type of media company" }, { "external_url" : "http://techcrunch.com/2012/06/17/search-and-social-how-two-will-soon-become-one/", "title" : "Guest post by CEO Ben Elowitz in TechCrunch" }, { "external_url" : "http://allthingsd.com/20120516/what-to-expect-when-facebook-is-expecting-five-predictions-for-facebooks-first-public-year/", "title" : "Guest post by CEO Ben Elowitz in AllThingsD" }, { "external_url" : "http://adage.com/article/digitalnext/facebook-biggest-player-advertising-s-540-billion-world/235708/", "title" : "Guest post by CEO Ben Elowitz in AdAge" }, { "external_url" : "http://www.businessinsider.com/facebook-captures-14-percent-of-our-online-attention-but-only-4-percent-of-ad-spending-online-2012-6", "title" : "Guest post by CEO Ben Elowitz in Business Insider" }, { "external_url" : "http://allfacebook.com/wetpaint-media-data_b75963", "title" : "AllFacebook coverage of Wetpaint" }, { "external_url" : "http://adage.com/article/digital/celeb-site-wetpaint-shows-media-profit-facebook/237828/", "title" : "Profile of Wetpaint in Ad Age" }, { "external_url" : "http://allthingsd.com/20121018/how-to-boost-your-facebook-traffic-tips-and-tricks-from-wetpaint/", "title" : "Interview with Wetpaint CEO Ben Elowitz in All Things D" }, { "external_url" : "http://www.xconomy.com/seattle/2012/10/19/wetpaint-starts-licensing-its-facebook-based-media-distribution-tech/", "title" : "Profile of Wetpaint in Xconomy" } ], "partners" : [] }

Need your help.需要你的帮助。 thanks.谢谢。

The reason for your error is that json.loads expects a string, which it then decodes into a python object.错误的原因是json.loads需要一个字符串,然后将其解码为 python 对象。 As a solution, you have two possible options.作为解决方案,您有两种可能的选择。

Option 1选项1
Pass a file object to json.load :将文件对象传递给json.load

tweets = json.load(input_file) 
>>> import json
>>> import pprint
>>> tweets = json.load(open('file.json'))
>>> pprint.pprint(tweets)
{'_id': {'$oid': '52cdef7c4bab8bd675297d8a'},
 'acquisition': {'acquired_day': 16,
                 'acquired_month': 12,
                 'acquired_year': 2013,
                 'acquiring_company': {'name': 'Viggle',
                                       'permalink': 'viggle'},
                 'price_amount': 30000000,
                 'price_currency_code': 'USD',
                 'source_description': ' Viggle Tries to Bulk Up Its Social '
                                       'TV Business by Buying Wetpaint',
                 'source_url': 'http://allthingsd.com/20131216/viggle-tries-to-bulk-up-its-social-tv-business-by-buying-wetpaint/?mod=atdtweet',
                 'term_code': 'cash_and_stock'},
 'acquisitions': [],
 'alias_list': '',
 'blog_feed_url': 'http://digitalquarters.net/feed/',
 'blog_url': 'http://digitalquarters.net/',
 'category_code': 'web',
 'competitions': [{'competitor': {'name': 'Wikia', 'permalink': 'wikia'}},
                  {'competitor': {'name': 'JotSpot', 'permalink': 'jotspot'}},
                  {'competitor': {'name': 'Socialtext',
                                  'permalink': 'socialtext'}},
                  {'competitor': {'name': 'Ning by Glam Media',
                                  'permalink': 'ning'}},
                  {'competitor': {'name': 'Soceeo', 'permalink': 'soceeo'}},
                  {'competitor': {'name': 'Yola', 'permalink': 'yola'}},
                  {'competitor': {'name': 'SocialGO',
                                  'permalink': 'socialgo'}},
                  {'competitor': {'name': 'IslamNor',
                                  'permalink': 'islamnor'}}],
 'created_at': {'$date': 1180075887000},
 'crunchbase_url': 'http://www.crunchbase.com/company/wetpaint',
 'deadpooled_year': 1,
 'description': 'Technology Platform Company',
 'email_address': 'info@wetpaint.com',
 'external_links': [{'external_url': 'http://www.geekwire.com/2011/rewind-ben-elowitz-wetpaint-ceo-building-type-media-company',
                     'title': 'GeekWire interview: Rewind - Ben Elowitz, '
                              'Wetpaint CEO, on building a new type of '
                              'media company'},
                    {'external_url': 'http://techcrunch.com/2012/06/17/search-and-social-how-two-will-soon-become-one/',
                     'title': 'Guest post by CEO Ben Elowitz in TechCrunch'},
                    {'external_url': 'http://allthingsd.com/20120516/what-to-expect-when-facebook-is-expecting-five-predictions-for-facebooks-first-public-year/',
                     'title': 'Guest post by CEO Ben Elowitz in AllThingsD'},
                    {'external_url': 'http://adage.com/article/digitalnext/facebook-biggest-player-advertising-s-540-billion-world/235708/',
                     'title': 'Guest post by CEO Ben Elowitz in AdAge'},
                    {'external_url': 'http://www.businessinsider.com/facebook-captures-14-percent-of-our-online-attention-but-only-4-percent-of-ad-spending-online-2012-6',
                     'title': 'Guest post by CEO Ben Elowitz in Business '
                              'Insider'},
                    {'external_url': 'http://allfacebook.com/wetpaint-media-data_b75963',
                     'title': 'AllFacebook coverage of Wetpaint'},
                    {'external_url': 'http://adage.com/article/digital/celeb-site-wetpaint-shows-media-profit-facebook/237828/',
                     'title': 'Profile of Wetpaint in Ad Age'},
                    {'external_url': 'http://allthingsd.com/20121018/how-to-boost-your-facebook-traffic-tips-and-tricks-from-wetpaint/',
                     'title': 'Interview with Wetpaint CEO Ben Elowitz in '
                              'All Things D'},
                    {'external_url': 'http://www.xconomy.com/seattle/2012/10/19/wetpaint-starts-licensing-its-facebook-based-media-distribution-tech/',
                     'title': 'Profile of Wetpaint in Xconomy'}],
 'founded_day': 17,
 'founded_month': 10,
 'founded_year': 2005,
 'funding_rounds': [{'funded_day': 1,
                     'funded_month': 10,
                     'funded_year': 2005,
                     'id': 888,
                     'investments': [{'company': None,
                                      'financial_org': {'name': 'Frazier '
                                                                'Technology '
                                                                'Ventures',
                                                        'permalink': 'frazier-technology-ventures'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Trinity '
                                                                'Ventures',
                                                        'permalink': 'trinity-ventures'},
                                      'person': None}],
                     'raised_amount': 5250000,
                     'raised_currency_code': 'USD',
                     'round_code': 'a',
                     'source_description': '',
                     'source_url': 'http://seattlepi.nwsource.com/business/246734_wiki02.html'},
                    {'funded_day': 1,
                     'funded_month': 1,
                     'funded_year': 2007,
                     'id': 889,
                     'investments': [{'company': None,
                                      'financial_org': {'name': 'Accel '
                                                                'Partners',
                                                        'permalink': 'accel-partners'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Frazier '
                                                                'Technology '
                                                                'Ventures',
                                                        'permalink': 'frazier-technology-ventures'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Trinity '
                                                                'Ventures',
                                                        'permalink': 'trinity-ventures'},
                                      'person': None}],
                     'raised_amount': 9500000,
                     'raised_currency_code': 'USD',
                     'round_code': 'b',
                     'source_description': '',
                     'source_url': 'http://pulse2.com/2007/01/09/wiki-builder-website-wetpaint-welcomes-95m-funding/'},
                    {'funded_day': 19,
                     'funded_month': 5,
                     'funded_year': 2008,
                     'id': 2312,
                     'investments': [{'company': None,
                                      'financial_org': {'name': 'DAG '
                                                                'Ventures',
                                                        'permalink': 'dag-ventures'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Accel '
                                                                'Partners',
                                                        'permalink': 'accel-partners'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Trinity '
                                                                'Ventures',
                                                        'permalink': 'trinity-ventures'},
                                      'person': None},
                                     {'company': None,
                                      'financial_org': {'name': 'Frazier '
                                                                'Technology '
                                                                'Ventures',
                                                        'permalink': 'frazier-technology-ventures'},
                                      'person': None}],
                     'raised_amount': 25000000,
                     'raised_currency_code': 'USD',
                     'round_code': 'c',
                     'source_description': 'Accel',
                     'source_url': 'http://www.accel.com/news/news_one_up.php?news_id=185'}],
 'homepage_url': 'http://wetpaint-inc.com',
 'image': {'available_sizes': [[[150, 75],
                                'assets/images/resized/0000/3604/3604v14-max-150x150.jpg'],
                               [[250, 125],
                                'assets/images/resized/0000/3604/3604v14-max-250x250.jpg'],
                               [[450, 225],
                                'assets/images/resized/0000/3604/3604v14-max-450x450.jpg']]},
 'investments': [],
 'milestones': [{'description': "Wetpaint named in Lead411's Hottest "
                                'Seattle Companies list',
                 'id': 5869,
                 'source_description': 'LEAD411 LAUNCHES "HOTTEST SEATTLE '
                                       'COMPANIES" AWARDS',
                 'source_text': None,
                 'source_url': 'http://www.lead411.com/seattle-companies.html',
                 'stoneable': {'name': 'Wetpaint', 'permalink': 'wetpaint'},
                 'stoneable_type': 'Company',
                 'stoned_acquirer': None,
                 'stoned_day': 8,
                 'stoned_month': 6,
                 'stoned_value': None,
                 'stoned_value_type': None,
                 'stoned_year': 2010},
                {'description': 'Site-Builder Wetpaint Makes One For '
                                'Itself, Using the Demand Media Playbook',
                 'id': 8702,
                 'source_description': 'All Things D',
                 'source_text': None,
                 'source_url': 'http://mediamemo.allthingsd.com/20100906/site-builder-wetpaint-makes-one-for-itself-using-the-demand-media-playbook/',
                 'stoneable': {'name': 'Wetpaint', 'permalink': 'wetpaint'},
                 'stoneable_type': 'Company',
                 'stoned_acquirer': None,
                 'stoned_day': 6,
                 'stoned_month': 9,
                 'stoned_value': None,
                 'stoned_value_type': None,
                 'stoned_year': 2010}],
 'name': 'Wetpaint',
 'number_of_employees': 47,
 'offices': [{'address1': '710 - 2nd Avenue',
              'address2': 'Suite 1100',
              'city': 'Seattle',
              'country_code': 'USA',
              'description': '',
              'latitude': 47.603122,
              'longitude': -122.333253,
              'state_code': 'WA',
              'zip_code': '98104'},
             {'address1': '270 Lafayette Street',
              'address2': 'Suite 505',
              'city': 'New York',
              'country_code': 'USA',
              'description': '',
              'latitude': 40.7237306,
              'longitude': -73.9964312,
              'state_code': 'NY',
              'zip_code': '10012'}],
 'overview': '<p>Wetpaint is a technology platform company that uses its '
             'proprietary state-of-the-art technology and expertise in '
             'social media to build and monetize audiences for digital '
             'publishers. Wetpaint’s own online property, Wetpaint '
             'Entertainment, an entertainment news site that attracts more '
             'than 12 million unique visitors monthly and has over 2 million '
             'Facebook fans, is a proof point to the company’s success in '
             'building and engaging audiences. Media companies can license '
             'Wetpaint’s platform which includes a dynamic playbook tailored '
             'to their individual needs and comprehensive training. Founded '
             'by Internet pioneer Ben Elowitz, and with offices in New York '
             'and Seattle, Wetpaint is backed by Accel Partners, the '
             'investors behind Facebook.</p>',
 'partners': [],
 'permalink': 'abc2',
 'phone_number': '206.859.6300',
 'products': [{'name': 'Wikison Wetpaint', 'permalink': 'wetpaint-wiki'},
              {'name': 'Wetpaint Social Distribution System',
               'permalink': 'wetpaint-social-distribution-system'}],
 'providerships': [],
 'relationships': [{'is_past': False,
                    'person': {'first_name': 'Michael',
                               'last_name': 'Howell',
                               'permalink': 'michael-howell'},
                    'title': 'Co-Founder and VP, Social and Audience '
                             'Development'},
                   {'is_past': False,
                    'person': {'first_name': 'Ben',
                               'last_name': 'Elowitz',
                               'permalink': 'ben-elowitz'},
                    'title': 'Co-Founder/CEO/Board of Directors'},
                   {'is_past': False,
                    'person': {'first_name': 'Rob',
                               'last_name': 'Grady',
                               'permalink': 'rob-grady'},
                    'title': 'COO/Board of Directors'},
                   {'is_past': False,
                    'person': {'first_name': 'Chris',
                               'last_name': 'Kollas',
                               'permalink': 'chris-kollas'},
                    'title': 'SVP, Strategy and Business Development'},
                   {'is_past': False,
                    'person': {'first_name': 'Theresia',
                               'last_name': 'Ranzetta',
                               'permalink': 'theresia-ranzetta'},
                    'title': 'Board'},
                   {'is_past': False,
                    'person': {'first_name': 'Gus',
                               'last_name': 'Tai',
                               'permalink': 'gus-tai'},
                    'title': 'Board Member'},
                   {'is_past': False,
                    'person': {'first_name': 'Len',
                               'last_name': 'Jordan',
                               'permalink': 'len-jordan'},
                    'title': 'Board'},
                   {'is_past': False,
                    'person': {'first_name': 'Alex',
                               'last_name': 'Weinstein',
                               'permalink': 'alex-weinstein'},
                    'title': 'Head of Technology and Product'},
                   {'is_past': True,
                    'person': {'first_name': 'Bert',
                               'last_name': 'Hogue',
                               'permalink': 'bert-hogue'},
                    'title': 'CFO'},
                   {'is_past': True,
                    'person': {'first_name': 'Brian',
                               'last_name': 'Watkins',
                               'permalink': 'brian-watkins'},
                    'title': 'CFO/ CRO'},
                   {'is_past': True,
                    'person': {'first_name': 'Rob',
                               'last_name': 'Grady',
                               'permalink': 'rob-grady'},
                    'title': 'Senior Vice President, Marketing'},
                   {'is_past': True,
                    'person': {'first_name': 'Werner',
                               'last_name': 'Koepf',
                               'permalink': 'werner-koepf'},
                    'title': 'VP, Technology and Product'},
                   {'is_past': True,
                    'person': {'first_name': 'Kevin',
                               'last_name': 'Flaherty',
                               'permalink': 'kevin-flaherty'},
                    'title': 'VP Marketing'},
                   {'is_past': True,
                    'person': {'first_name': 'Alex',
                               'last_name': 'Berg',
                               'permalink': 'alex-berg'},
                    'title': 'VP User Experience'},
                   {'is_past': True,
                    'person': {'first_name': 'Steve',
                               'last_name': 'McQuade',
                               'permalink': 'steve-mcquade'},
                    'title': 'VP Engineering'},
                   {'is_past': True,
                    'person': {'first_name': 'Susan',
                               'last_name': 'Mulcahy',
                               'permalink': 'susan-mulcahy'},
                    'title': 'Executive Editor'},
                   {'is_past': True,
                    'person': {'first_name': 'Chris',
                               'last_name': 'Kollas',
                               'permalink': 'chris-kollas'},
                    'title': 'VP Business Development'}],
 'screenshots': [{'attribution': None,
                  'available_sizes': [[[150, 86],
                                       'assets/images/resized/0016/0929/160929v2-max-150x150.png'],
                                      [[250, 143],
                                       'assets/images/resized/0016/0929/160929v2-max-250x250.png'],
                                      [[450, 258],
                                       'assets/images/resized/0016/0929/160929v2-max-450x450.png']]}],
 'tag_list': 'wiki, seattle, elowitz, media-industry, media-platform, '
             'social-distribution-system',
 'total_money_raised': '$39.8M',
 'twitter_username': 'BachelrWetpaint',
 'updated_at': 'Sun Dec 08 07:15:44 UTC 2013',
 'video_embeds': []}
>>>
>>> list(tweets.keys())
['overview', 'acquisition', 'offices', 'crunchbase_url', 'founded_month', 'blog_feed_url', 'image', 'investments', 'partners', 'twitter_username', 'category_code', 'milestones', 'permalink', 'homepage_url', 'competitions', 'screenshots', 'founded_year', 'funding_rounds', 'number_of_employees', 'video_embeds', '_id', 'providerships', 'relationships', 'name', 'deadpooled_year', 'phone_number', 'products', 'acquisitions', 'created_at', 'email_address', 'blog_url', 'external_links', 'description', 'tag_list', 'updated_at', 'total_money_raised', 'alias_list', 'founded_day']

Option 2选项 2
Pass a string to json.loads :将字符串传递给json.loads

tweets = json.loads(input_file.read())
 tweets = json.loads(input_file)

你想要json.loads(input_file.read())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用tika解析Python中的文档时出现“ TypeError:预期的字符串或缓冲区” - “TypeError: expected string or buffer” when using tika to parse documents in Python Python(json):TypeError:期望的字符串或缓冲区 - Python (json) : TypeError: expected string or buffer 收到TypeError:尝试解析json中的时间字符串时出现预期的字符串或缓冲区? - Getting TypeError: expected string or buffer when trying to parse time string in the json? JSON TypeError:预期的字符串或缓冲区 - JSON TypeError: expected string or buffer Python TypeError:期望的字符串或缓冲区 - Python TypeError: expected string or buffer Python-TypeError:预期的字符串或缓冲区 - Python - TypeError: expected string or buffer TypeError:Python中预期的字符串或缓冲区 - TypeError: expected string or buffer in Python TypeError:在python中使用正则表达式时期望的字符串或缓冲区 - TypeError: expected string or buffer while using regular expression in python 使用管理员保存HStoreField时出错:TypeError:预期的字符串或缓冲区 - Error when saving HStoreField using Admin: TypeError: expected string or buffer Python2.7.11:类型错误:预期的字符串或缓冲区 - Python2.7.11: TypeError: expected string or buffer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM