2013-05-02 163 views
14

我想將以下json結構轉換爲java中的BasicDBOject並插入到mongo數據庫中。將JSON結構轉換爲BasicDBObject

我的JSON結構是

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

回答

28

com.mongodb.util.JSON具有解析方法。

BasicDBObject實現DBOBJECT

Object o = com.mongodb.util.JSON.parse("Your JSON structure or JSONObj.toString()"); 
DBObject dbObj = (DBObject) o; 
0
com.mongodb.util.JSON.parse 

已被棄用

版本3.6.1使用後:

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

請按這裏:deprecated-list