我有一个列表,其中包含这样的字典:
json_obj = [[{'id': None},{'id': '5b98d01c0835f23f538cdcab'},{'id': '5b98d0440835f23f538cdcad'},{'id': '5b98d0ce0835f23f538cdcb9'}],[{'id': None},{'id': '5b98d01c0835f23f538cd'},{'id': '5b98d0440835f23f538cd'},{'id': '5b98d0ce0835f23f538cdc'}]]
我希望它存储在这样的列表列表中:
y=[['None','5b98d01c0835f23f538cdcab','5b98d0440835f23f538cdcad','5b98d0ce0835f23f538cdcb9'],['None','5b98d01c0835f23f538cd','5b98d0440835f23f538cd','5b98d0ce0835f23f538cdc']]
为了从我尝试过的字典中读取 id
for d in json_obj:
print(d['id'])
但是我在上面的代码中看到了这个错误:
TypeError: list indices must be integers or slices, not str
心有法竹
慕后森
相关分类