15

我想将以下json结构转换为BasicDBOjectjava 并插入 mongo db。

我的 JSON 结构是

{
    "it": {
        "batch": "2013",
        "students": [
            {
                "name": "joe"
            },
            {
                "name": "john"
            }
        ]
    }
}
4

2 回答 2

31

com.mongodb.util.JSON 有一个 parse 方法。

BasicDBObject 实现 DBObject

Object o = com.mongodb.util.JSON.parse("Your JSON structure or JSONObj.toString()");
DBObject dbObj = (DBObject) o;
于 2013-05-02T08:42:35.537 回答
6
com.mongodb.util.JSON.parse 

已弃用

在版本 3.6.1 之后使用:

String json = "{"name": "joe"}";
Object o = BasicDBObject.parse(json);

在此处关注:弃用列表

于 2018-01-12T21:51:40.147 回答