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,这是容易出错和性能问题。