[英]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.