首页 > 解决方案 > 如何从请求中解析python列表类型

问题描述

我想使用比特币 api。收到的数据如下:

[
  {
    'market': 'KRW-BTC',
    'candle_date_time_utc': '2020-05-04T03:17:00',
    'candle_date_time_kst': '2020-05-04T12:17:00',
    'opening_price': 10662000.0,
    'high_price': 10676000.0,
    'low_price': 10662000.0,
    'trade_price': 10675000.0,
    'timestamp': 1588562256134,
    'candle_acc_trade_price': 18269778.31894,
    'candle_acc_trade_volume': 1.71334319,
    'unit': 1
  }
]

这只是一种列表类型的数据。

我想在下面解析这些数据:

['market' : "KRW-BTC" , 'candle_date_time_utc': '2020-05-04T03:17:00' ~~~ ]

我该怎么做呢?

标签: python

解决方案


这是如何访问字典列表中的值。

r = [{'market': 'KRW-BTC', 'candle_date_time_utc': '2020-05-04T03:17:00', 'candle_date_time_kst': '2020-05-04T12:17:00', 'opening_price': 10662000.0, 'high_price': 10676000.0, 'low_price': 10662000.0, 'trade_price': 10675000.0, 'timestamp': 1588562256134, 'candle_acc_trade_price': 18269778.31894, 'candle_acc_trade_volume': 1.71334319, 'unit': 1}]
# r < this is the list  [0] < the index of the dictionary in the list 'market' the key to the value you'd like to extract
print (r[0]['market'])
print (r[0]['candle_date_time_utc'])

推荐阅读