【问题标题】:Convert Json into Dictionary in Python在 Python 中将 Json 转换为字典
【发布时间】:2015-01-04 16:36:49
【问题描述】:

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

Python:

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

控制台:

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

【问题讨论】:

  • 您是否查看过例如json?!

标签: python json mongodb dictionary


【解决方案1】:

这样就可以了:

import json
q = json.loads(content)

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 2011-01-29
      • 2019-04-19
      • 2020-08-08
      • 2017-07-02
      • 2014-02-26
      • 2018-05-04
      • 1970-01-01
      相关资源
      最近更新 更多