1
我使用CouchbaseLite構建NoSQL類型的嵌入式數據庫。下載了1.3版本couchbase-lite-java-1.3.1-community.zip
的庫,並將它們添加到eclipse中的Java項目中。使用Jackson庫創建JAVA使用JSON文件創建地圖
以下是我想要實現的任務嗎?
- 讀以.json文件(讓我們假設該文件路徑
J:/temp/sample.json
) - 將其轉爲地圖
- 插入CouchBase數據庫。
以下是我試過的代碼:
CouchDBManager dbManager = new CouchDBManager();
Database myDB = dbManager.createDataBase("atempt1");
// first step
File f = new File("J:/temp/sample.json");
// code to read the content of a file
// second step
ObjectNode objectNode1 = mapper.createObjectNode();
// add code to covert the json content read from the file to Map
// third step
Document doc = myDB.createDocument();
doc.putProperties(map); // putProperties expectes Map object
所以,請幫我在讀json
文件,並使用Jackson
庫,將其轉換爲Map
,這樣我可以創造並插入文檔進CouchbaseLite D B。
注:Jackson
庫是CouchBaseLite
我下載的部分,所以我想它周圍的解決方案。 I don't want to use custom processing
的JSON文件並將其轉換爲Map,這是容易出錯和性能問題。