MongoDB DBObject 和 org.json.JSONObject 之间的桥梁?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12792632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 15:56:35  来源:igfitidea点击:

A bridge between MongoDB DBObject and org.json.JSONObject?

javajsonmongodborg.json

提问by Eran Medan

I'm using the native MongoDB driver and API, which uses com.mongodb.DBObjectto represent JSON objects, however for general purpose I have usage of org.json.JSONOBject.

我正在使用本机 MongoDB 驱动程序和 API,它用于com.mongodb.DBObject表示 JSON 对象,但是出于一般目的,我使用org.json.JSONOBject.

I thought of replacing it and using DBObject as a general JSON library, but it doesn't feel right.

想过把它替换掉,用DBObject作为通用的JSON库,但是感觉不太对。

But to interop with the two, the low level String/Map format/parse interface is used, which I don't like either.

但是为了与两者互操作,使用了低级 String/Map 格式/解析接口,我也不喜欢它。

Is there a known library out there that implements both interfaces for easier interoperability?

是否有一个已知的库可以实现两个接口以实现更轻松的互操作性?

采纳答案by shelman

In general, converting between BSON and JSON was intended to be a painless operation, so you shouldn't have to write more classes. Does thisanswer help at all?

一般来说,在 BSON 和 JSON 之间进行转换是一种轻松的操作,因此您不必编写更多的类。请问这个答案帮助呢?