2015-01-04 138 views
0

以下Json是通过查询collection.find()方法从Mongodb获得的。如何将此Json转换为Python中的Dictionary?我想将BMW作为钥匙和Series 3作为我的字典中的价值。将Json转换为Python中的字典

的Python:

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

控制台:

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

你进去看了看,例如,[ 'json'](HTTP S://docs.python.org/2/library/json.html)? – jonrsharpe

回答

1

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

+0

你太棒了 – Taewan

4

这将做到这一点:

import json 
q = json.loads(content)