将 Json 转换为 Python 中的字典

Convert Json into Dictionary in Python

以下 Json 来自 Mongodb 通过查询 collection.find() 方法。如何将此 Json 转换为 Python 中的字典?我想在我的字典中将 BMW 映射为键,将 Series 3 映射为值。

蟒蛇:

content = list(collection.find({"_id": "sample_abc"}, {"Car":1, "_id":0}))
print (content)

控制台:

[{'Car': [{'BMW': 'series 3'}, {'Audi': 'A4'}]}]

这样做就可以了:

import json
q = json.loads(content)

content[0]['Car'][0] 可能是 {'BMW': 'series 3'}