Python 从API返回的列表中获取值

Python 从API返回的列表中获取值,python,list,api,Python,List,Api,我挣扎着从API调用返回的列表中提取某个值。以下是列表(缩短版本): 并通过以下方式返回: client.Position.Position_get(filter=json.dumps({'symbol': 'XBTUSD'})).result() 我希望将“avgEntryPrice”提取为变量,提前感谢各位 您将达到如下值: list=[{'account':231584,'simpleCost':0.0,'simpleValue':0.0,'avgEntryPrice':0.0,…}]

我挣扎着从API调用返回的列表中提取某个值。以下是列表(缩短版本):

并通过以下方式返回:

client.Position.Position_get(filter=json.dumps({'symbol': 'XBTUSD'})).result()

我希望将“avgEntryPrice”提取为变量,提前感谢各位

您将达到如下值:

list=[{'account':231584,'simpleCost':0.0,'simpleValue':0.0,'avgEntryPrice':0.0,…}]
列表[0][“avgEntryPrice”]
因为列表中只有字典作为其项。因此,您需要访问列表的第一项,然后使用该字典中的键访问所需的值

如果您有多个词典,您可以这样做:

list=[{'account':231584,'simpleCost':0.0,'simpleValue':0.0,{'account':231584,'simpleCost':0.0,'simpleValue':0.0},{'account':231584,'simpleCost':0.0,'simpleValue':0.0,'avgEntryPrice':0.0},{'account 231584,'simpleCost':0.0,'simpleCost':0.0,'simpleValue':0}]
avgEntryPrices=[列表中项目的项目[“avgEntryPrices”]

这将返回列表中每个词典的avgEntryPrice

您将获得如下值:

list=[{'account':231584,'simpleCost':0.0,'simpleValue':0.0,'avgEntryPrice':0.0,…}]
列表[0][“avgEntryPrice”]
因为列表中只有字典作为其项。因此,您需要访问列表的第一项,然后使用该字典中的键访问所需的值

如果您有多个词典,您可以这样做:

list=[{'account':231584,'simpleCost':0.0,'simpleValue':0.0,{'account':231584,'simpleCost':0.0,'simpleValue':0.0},{'account':231584,'simpleCost':0.0,'simpleValue':0.0,'avgEntryPrice':0.0},{'account 231584,'simpleCost':0.0,'simpleCost':0.0,'simpleValue':0}]
avgEntryPrices=[列表中项目的项目[“avgEntryPrices”]

这将返回列表中每个词典的avgEntryPrice

列表中是否有多个词典?是否要获取avgEntryPrice的列表?列表中是否有多个词典?是否要获取
avgEntryPrice
的列表?返回KeyError:“avgEntryPrice”unfortunelty:/,并提供它正在工作的示例数据。您能否检查示例数据和api返回的数据是否匹配?是否每个dict中都有avgEntryPrice键?返回KeyError:“avgEntryPrice”unfortunelty:/以及它工作时提供的示例数据。您能否检查示例数据和api返回的数据是否匹配?每个dict都有avgEntryPrice密钥吗?
client.Position.Position_get(filter=json.dumps({'symbol': 'XBTUSD'})).result()