在Python中将Json转换为Dictionary

时间:2015-01-04 16:36:49

标签: python json mongodb dictionary

以下Json来自Mongodb,通过查询collection.find()方法。如何在Python中将此Json转换为Dictionary?我想把宝马作为关键,将3系列作为我字典中的值。

的Python:

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

控制台:

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

2 个答案:

答案 0 :(得分:4)

这样做:

import json
q = json.loads(content)

答案 1 :(得分:1)

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