2017-09-23 24 views
-1

私はPythonを初めて使用しています& Json処理。私はPython 2.7を使用しています。私は次のコードを実行すると、私はいくつかのエラーメッセージが出ます:Pythonを使用してJSONを解析しようとすると "TypeError:expected string or buffer"

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" 

エラーメッセージは以下の通りです:

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 

私は次のコードが、intial 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" 

マイ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" : "[email protected]", "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" : [] } 

あなたの助けが必要です。ありがとう。

答えて

0

エラーの理由は、json.loadsが文字列を必要としていることです。この文字列はPythonオブジェクトにデコードされます。解決策として、2つの選択肢があります。

オプション1
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': '[email protected]', 
'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'] 

オプション2
json.loadsに文字列を渡し:

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

を望んでいました。あなたの応答に感謝します。上記の両方のオプションが機能しています。私がキーを表示すると、次のキーだけが得られます: – Ravi

+0

[u'category_code '、u'crunchbase_url'、u'video_embeds '、u'overview'、u'image '、u'updated_at'、u'funding_rounds '、u 'total_money_raised'、u'email_address '、u'alias_list'、u'relationships '、u'partners'、u'screenshots '、u'founded_day'、u'competitions '、u'blog_feed_url'、u'providerships '、u u'description '、u'deadpooled_year'、u'twitter_username '、u'milestones'、u'external_links '、 – Ravi

+0

u'number_of_employees'、u'founded_year '、u'founded_month'、 ' 'u'cid'、 'u'created_at'、u'homepage_url '、u'products'、u'blog_url '、u'tag_list'、u'investments '、および' u'acquisition '] – Ravi

0
tweets = json.loads(input_file) 

あなたは、私が理解しjson.loads(input_file.read())

+0

私は理解しています。ご回答いただきありがとうございます。しかし、いくつかのjsonキーがありません。なぜ分からないの? – Ravi

+0

[u'category_code '、u'crunchbase_url'、u'video_embeds '、u'overview'、u'image '、u'updated_at'、 'u'funding_rounds'、u'total_money_raised '、u'email_address'、u'alias_list '、u'relationships'、u'partners '、u'scoundhots'、u'founded_day '、u'competitions'、u'blog_feed_url '、u'providerships'、u'offices '、u'phone_number'、u'description '、u'deadpooled_year'、u'twitter_username '、u'milestones'、u'external_links '、 – Ravi

+0

u'number_of_employees'、u'founded_month '、u'founded_month'、u'acquisitions '、u'permalink'、u ' _id '、u'name'、u'created_at '、u'homepage_url'、u'products '、u'blog_url'、u'tag_list '、u'investments'、u'acquisition '] – Ravi

関連する問題