python - 从python中的嵌套元组中获取值
问题描述
我有一个来自 api 的 json 响应,我需要从以下位置获取“askPrice”值:
dict_items(
[
('SPY',
{
'assetType': 'ETF',
'assetMainType': 'EQUITY',
'cusip': '78462F103',
'assetSubType': 'ETF',
'symbol': 'SPY',
'description': 'SPDR S&P 500',
'bidPrice': 435.31,
'bidSize': 2100,
'bidId': 'T',
'askPrice': 435.33,
'askSize': 200,
'askId': 'P',
'lastPrice': 435.32,
'lastSize': 0,
... ,
'delayed': True,
'realtimeEntitled': False
}
)
]
)
我的代码是:
quote = c.get_quotes("SPY")
resp = quote.json().items()
print(pd.json_normalize(resp['SPY']['AskPrice'],level=2))
但是python解释器显示错误:
TypeError:“dict_items”对象不可下标
我为这个简单的问题道歉。
解决方案
推荐阅读
- php - 从控制器返回数据 - Codeigniter
- mysql - 在没有死锁的情况下循环插入MySql数据库
- php - 如果 1 大于其他,则 sql 查询交换列
- asp.net-core - AspNet Core SignalR KeepAlive 超时的一些问题
- c# - AppDomain.CreateInstanceFromAndUnwrap 问题与 keydown
- objective-c - 从 Objective-c 返回数据到 react-native
- swiftui - SwiftUI 图像未显示在 xcode 预览画布中
- maven - liferay-maven-plugin + direct-deploy configuration for DXP
- amazon-s3 - S3 + Cloudfront:允许文件但阻止文件夹
- python - Pandas:使用条件过滤器对动态选择的列进行分组操作