python - 如何从请求中解析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' ~~~ ]
我该怎么做呢?
解决方案
这是如何访问字典列表中的值。
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'])
推荐阅读
- python - 用 Beautiful Soup 创建 CSV 文件
- javascript - 从 AWS S3 下载文件如何正确使用 JS
- plantuml - 注释中文本块的植物背景颜色
- python-3.x - 问:在 Python 中将字符串写入 HID 设备?
- ubuntu - 我在 Ubuntu 服务器上使用带有 certbot 的 Nginx 设置 https 失败并出现 ERR_ADDRESS_UNREACHABLE
- c++ - 获取所有进程窗口名称的列表
- python - 如何自动选择一个对象FK项目(django)
- javascript - 如何让约会更漂亮?
- google-bigquery - BigQuery 中 CONDITIONAL_TRUE_EVENT 的替代方案,带有 LAG() 函数?
- sql - 完全加入没有给我想要的结果