[英]create JAVA Map out of JSON file using Jackson libraries
我正在使用CouchbaseLite來構建NoSQL類型的嵌入式數據庫。 下載了1.3版本couchbase-lite-java-1.3.1-community.zip
庫,並將它們添加到eclipse中的Java項目中。
以下是我想要實現的任務?
J:/temp/sample.json
) 以下是我嘗試過的代碼:
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 DB。
注意: Jackson
庫是我下載的CouchBaseLite
一部分,所以我想要一個解決方案。 我don't want to use custom processing
JSON文件的don't want to use custom processing
並將其轉換為Map,這容易出錯並且性能問題。
請查看以下鏈接中的Jackson數據綁定文檔:
map = mapper.readValue(new File("J:/temp/sample.json"), HashMap.class);
返回一張地圖。
參考:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.