将 BSON 文件转换为 JSON 会导致内容丢失
Converting BSON file to JSON results in missing content
我正在尝试将 .bson 文件转换为 .json。我试过使用 bson 访问 json 网站,它们 return 与 python 代码相同。
bson_file = open('fishes.bson', 'rb')
b = bson.loads(bson_file.read())
print(b)
这个returns:
{'_id': b'5ac88a55eadcdf42044615bb', 'imgurl': 'http://www.fishbase.org/images/thumbnails/jpg/tn_Prweb_u0.jpg', 'rarity': 1, 'id': 0, 'length': 3.1, 'name': 'Aapticheilichthys websteri', 'fishLength': 3.1}
bson 文件是 2.68 MB,所以我认为它不应该只有那个。 bson文件是否无效?我还能如何访问 bson 文件?
我正在使用 python 3.8.1.
好吧,bson 库 确实 包含我的答案。
bson.decode_all(bson_file)
这对我没用,因为显然我的环境有问题。但是其他人帮助了我,运行 代码有效。现在我必须弄清楚我的环境出了什么问题...
我正在尝试将 .bson 文件转换为 .json。我试过使用 bson 访问 json 网站,它们 return 与 python 代码相同。
bson_file = open('fishes.bson', 'rb')
b = bson.loads(bson_file.read())
print(b)
这个returns:
{'_id': b'5ac88a55eadcdf42044615bb', 'imgurl': 'http://www.fishbase.org/images/thumbnails/jpg/tn_Prweb_u0.jpg', 'rarity': 1, 'id': 0, 'length': 3.1, 'name': 'Aapticheilichthys websteri', 'fishLength': 3.1}
bson 文件是 2.68 MB,所以我认为它不应该只有那个。 bson文件是否无效?我还能如何访问 bson 文件? 我正在使用 python 3.8.1.
好吧,bson 库 确实 包含我的答案。
bson.decode_all(bson_file)
这对我没用,因为显然我的环境有问题。但是其他人帮助了我,运行 代码有效。现在我必须弄清楚我的环境出了什么问题...