我通过python标识为列表的API提取数据,但似乎不像一个。
这是返回数据的示例:
[{'product_id': '41111', 'type': 'configurable', 'set': '4', 'sku': 'CM5555-CONF', 'position': '1'}, {'product_id': '42222', 'type': 'configurable', 'set': '4', 'sku': 'CM6666-CONF', 'position': '1'}
这是一个称为temp的变量。
当我做print(type(temp))时,<class 'list'>
返回。
我正在尝试访问所有产品ID的列表,因此可以将它们提供给API的其他请求。
当我这样做时print(temp[::1])
,将返回整个列表(或任何列表),就像我print(temp)
自己做的那样。
我如何仅自己打印product_id列表?
您是正确的,它是一个列表,但是列表中的{}是字典。您必须参考它们的密钥才能将其拔出。尝试:
for datadict in temp:
print(datadict['product_id'])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句