bson.josn_util返回一个字符串而不是列表

问题描述 投票:0回答:1

我正在尝试将BSON从MongoDB转换为JSON,以使用bson.json_util.dumps但是此函数返回的是字符串而不是列表。

即[{“ id”:“ demo”},{“ id”:“ demo_new”}]]->'[{“ id”:“ demo”},{“ id”:“ demo_new”}]'

]

尽管很难迭代,因为它从字符串而不是列表中获取单个元素。

正在迭代->'[','{','“',” i“,” d“等希望迭代为-> {“ id”:“ demo”},{“ id”:“ demo_new”}

任何建议如何将字符串返回列表?

python json string list bson
1个回答
0
投票

我遇到了同样的问题。

我的解决方法是:

from bson import encode, decode
json = decode(encode(...))

...是您放置查询的位置。

© www.soinside.com 2019 - 2024. All rights reserved.