如何提取此json列表中的第一项

时间:2019-01-14 18:23:55

标签: python json

我有这个json,我试图在python的列表列表中提取第一个元素/列表...如何提取ads_list中的第一个项目?

我可以使用任何内置函数来提取json文件中的第一项吗?除了简单地像数组一样遍历整个数组之外,我还需要其他东西。

P.S。我缩短了json数据

这是列表。

{  
   u'data':{  
      u'ad_list':[  
         {  
            u'data':{  
               u'require_feedback_score':0,
               u'hidden_by_opening_hours':False,
               u'trusted_required':False,
               u'currency':u'EGP',
               u'require_identification':False,
               u'is_local_office':False,
               u'first_time_limit_btc':None,
               u'city':u'',
               u'location_string':u'Egypt',
               u'countrycode':u'EG',
               u'max_amount':u'20000',
               u'lon':0.0,
               u'sms_verification_required':False,
               u'require_trade_volume':0.0,
               u'online_provider':u'SPECIFIC_BANK',
               u'max_amount_available':u'20000',
               u'msg':               u" \u2605\u2605\u2605\u2605\u2605 \u0645\u0631\u062d\u0628\u0627 \u2605\u2605\u2605\u2605\u2605\r\n\r\n\u0625\u0630\u0627 \u0643\u0646\u062a \u062a\u0631\u063a\u0628 \u0641\u064a \u0628\u064a\u0639 \u0627\u0648 \u0634\u0631\u0627\u0621 \u0627\u0644\u0628\u062a\u0643\u0648\u064a\u0646 \u062a\u0648\u0627\u0635\u0644 \u0645\u0639\u064a \u0648\u0633\u0623\u0642\u0648\u0645 \u0628\u062e\u062f\u0645\u062a\u0643\r\n\u0644\u0644\u062a\u0648\u0627\u0635\u0644:               https:               //tawk.to/hanyibrahim\r\n  \u0627\u0644\u062e\u064a\u0627\u0631 \u0644\u0644\u062a\u062d\u0648\u064a\u0644:               \u0627\u0644\u0628\u0646\u0643 \u0627\u0644\u062a\u062c\u0627\u0631\u064a \u0627\u0644\u062f\u0648\u0644\u064a \u0627\u0648\u0641\u0648\u062f\u0627\u0641\u0648\u0646 \u0643\u0627\u0634 \u0627\u0648 \u0627\u062a\u0635\u0627\u0644\u0627\u062a \u0641\u0644\u0648\u0633 \u0627\u0648 \u0627\u0648\u0631\u0627\u0646\u062c \u0645\u0648\u0646\u064a\r\n\r\n'' \u0634\u0643\u0631\u0627 ''\r\n\r\n\r\n \u2605\u2605\u2605\u2605\u2605 Hello \u2605\u2605\u2605\u2605\u2605\r\n\r\nIf you would like to trade Bitcoins please let me know and I will help you\r\nconnect:               https:               //tawk.to/hanyibrahim\r\nOption transfer:Bank CIB Or Vodafone Cash Or Etisalat Flous Or Orange Money\r\n'' Thank ''",
               u'volume_coefficient_btc':u'1.50',
               u'profile':{  
                  u'username':u'hanyibrahim11',
                  u'feedback_score':100,
                  u'trade_count':u'3000+',
                  u'name':u'hanyibrahim11 (3000+; 100%)',
                  u'last_online':                  u'2019-01-14T17:54:52+00:00                  '}, u'                  bank_name':u'CIB_Vodafone Cash_Etisalat Flous_Orange Money',
                  u'trade_type':u'ONLINE_BUY',
                  u'ad_id':803036,
                  u'temp_price':u'67079.44',
                  u'payment_window_minutes':90,
                  u'min_amount':u'50',
                  u'limit_to_fiat_amounts':u'',
                  u'require_trusted_by_advertiser':False,
                  u'temp_price_usd':u'3738.54',
                  u'lat':0.0,
                  u'visible':True,
                  u'created_at':                  u'2018-07-25T08:12:21+00:00                  ', u'                  atm_model':None,
                  u'is_low_risk':True
               },
               u'actions':{  
                  u'public_view':                  u'https://localbitcoins.com/ad/803036'
               }
            },
            {  
               u'data':{  
                  u'require_feedback_score':0,
                  u'hidden_by_opening_hours':False,
                  u'trusted_required':False,
                  u'currency':u'EGP',
                  u'require_identification':False,
                  u'is_local_office':False,
                  u'first_time_limit_btc':None,
                  u'city':u'',
                  u'location_string':u'Egypt',
                  u'countrycode':u'EG',
                  u'max_amount':u'20000',
                  u'lon':0.0,
                  u'sms_verification_required':False,
                  u'require_trade_volume':0.0,
                  u'online_provider':u'CASH_DEPOSIT',
                  u'max_amount_available':u'20000',
                  u'msg':u'QNB,
                  CIB deposite- Vodafone Cash - Etisalat Felous - Orange Money - Western Union - Money Gram \r\n- Please do not entiate a new trade request if you are not serious to finalize it.',
                  u'volume_coefficient_btc':u'1.50',
                  u'profile':{  
                     u'username':u'Haboush',
                     u'feedback_score':99,
                     u'trade_count':u'500+',
                     u'name':u'Haboush (500+; 99%)',
                     u'last_online':                     u'2019-01-14T16:48:52+00:00                     '}, u'                     bank_name':u'QNB\u2714CIB\u2714Vodafone\u2714Orange\u2714Etisalat\u2714WU',
                     u'trade_type':u'ONLINE_BUY',
                     u'ad_id':719807,
                     u'temp_price':u'66860.18',
                     u'payment_window_minutes':270,
                     u'min_amount':u'100',
                     u'limit_to_fiat_amounts':u'',
                     u'require_trusted_by_advertiser':False,
                     u'temp_price_usd':u'3726.32',
                     u'lat':0.0,
                     u'visible':True,
                     u'created_at':                     u'2018-03-24T19:29:08+00:00                     ', u'                     atm_model':None,
                     u'is_low_risk':True
                  },
                  u'actions':{  
                     u'public_view':                     u'https://localbitcoins.com/ad/719807'
                  }
               },

                                                            }
                                                         ],
                                                         u'ad_count':17
                                                      }
                                                   }

1 个答案:

答案 0 :(得分:1)

假设您的数据结构存储在变量j中,则可以使用j['data']['ad_list'][0]ad_list键中提取第一项。如果try-except可以为空,请使用IndexError块捕获可能的ad_list异常。