我想将以下json结构转换为BasicDBOjectjava并插入到mongo db中.
我的JSON结构是
{
"it": {
"batch": "2013",
"students": [
{
"name": "joe"
},
{
"name": "john"
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
Alp*_*per 31
com.mongodb.util.JSON有一个解析方法.
BasicDBObject实现DBObject
Object o = com.mongodb.util.JSON.parse("Your JSON structure or JSONObj.toString()");
DBObject dbObj = (DBObject) o;
Run Code Online (Sandbox Code Playgroud)
小智 5
Run Code Online (Sandbox Code Playgroud)com.mongodb.util.JSON.parse已弃用
3.6.1 版本后使用:
String json = "{"name": "joe"}";
Object o = BasicDBObject.parse(json);
Run Code Online (Sandbox Code Playgroud)
按照这里:弃用列表