python - 访问 Python 数组中的数据
问题描述
我正在提取库存数据,我需要访问“callExpDateMap”中出现的第一个选项。但是,我不确定。
我试图通过调用访问第一个选项的数据:
xyz = json.dumps(data, indent=4)
print(xyz)
{
"symbol": "GOEV",
"status": "SUCCESS",
"underlying": null,
"strategy": "SINGLE",
"interval": 0.0,
"isDelayed": true,
"isIndex": false,
"interestRate": 0.1,
"underlyingPrice": 10.969999999999999,
"volatility": 29.0,
"daysToExpiration": 0.0,
"numberOfContracts": 5,
"putExpDateMap": {},
"callExpDateMap": {
"2021-06-18:3": {
"11.5": [
{
"putCall": "CALL",
"symbol": "GOEV_061821C11.5",
"description": "GOEV Jun 18 2021 11.5 Call",
"exchangeName": "OPR",
"bid": 0.6,
"ask": 0.7,
"last": 0.6,
"mark": 0.65,
"bidSize": 4,
"askSize": 138,
"bidAskSize": "4X138",
"lastSize": 0,
"highPrice": 1.0,
"lowPrice": 0.1,
"openPrice": 0.0,
"closePrice": 0.1,
"totalVolume": 4416,
"tradeDate": null,
"tradeTimeInLong": 1623787194008,
"quoteTimeInLong": 1623787198521,
"netChange": 0.5,
"volatility": 195.881,
"delta": 0.448,
"gamma": 0.183,
"theta": -0.111,
"vega": 0.004,
"rho": 0.0,
"openInterest": 100,
"timeValue": 0.6,
"theoreticalOptionValue": 0.654,
"theoreticalVolatility": 29.0,
"optionDeliverablesList": null,
"strikePrice": 11.5,
"expirationDate": 1624046400000,
"daysToExpiration": 3,
"expirationType": "R",
"lastTradingDay": 1624060800000,
"multiplier": 100.0,
"settlementType": " ",
"deliverableNote": "",
"isIndexOption": null,
"percentChange": 500.0,
"markChange": 0.55,
"markPercentChange": 554.2,
"nonStandard": false,
"inTheMoney": false,
"mini": false
}
]
},
要访问第一项,我打电话给:
print(xyz['callExpDateMap'][0])
但是,那行不通。如何将数组中的第一项传递给单独的变量?
解决方案
也许这会对你有所帮助
callExpDateMap = list(data['callExpDateMap'].values())
print(callExpDateMap[0])
推荐阅读
- angular - 产品配置文件性能不佳
- linux - 如何在具有部分文件名的目录中查找最新创建的 .gz 文件的文件名
- angular - 角度路径中的导航错误
- sql-server - 动态数据透视表 SQL Server 存储过程或在 Crysal Reports 中
- mysql - 如何使用 Entity Framework 6 MySQL 更新记录
- jenkins - 使用 deleteDir 的 Jenkins 管道“无法删除”
- javascript - 如何附加谷歌街景图像?
- android - 一个地理围栏用于多个标记
- scala - Scala抽象类实例
- java - 如何根据行项目的属性设置 TableCell 样式?