[英]create JAVA Map out of JSON file using Jackson libraries
I am using CouchbaseLite to build embedded database of NoSQL type. 我正在使用CouchbaseLite来构建NoSQL类型的嵌入式数据库。 Downloaded libraries for 1.3 version
couchbase-lite-java-1.3.1-community.zip
and added them to my Java project in eclipse. 下载了1.3版本
couchbase-lite-java-1.3.1-community.zip
库,并将它们添加到eclipse中的Java项目中。
Following are the tasks I want to achieve? 以下是我想要实现的任务?
J:/temp/sample.json
) J:/temp/sample.json
) Following is the code that I tried: 以下是我尝试过的代码:
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
So, kindly help me in reading the json
file and convert it to Map
using Jackson
libraries so that I can create and insert the document into CouchbaseLite DB. 所以,请帮助我阅读
json
文件并使用Jackson
库将其转换为Map
以便我可以创建文档并将其插入CouchbaseLite DB。
Note: Jackson
libraries are part of CouchBaseLite
that I downloaded, so I want a solution around it. 注意:
Jackson
库是我下载的CouchBaseLite
一部分,所以我想要一个解决方案。 I don't want to use custom processing
of JSON file and convert it to Map, which is error prone and performance issue. 我
don't want to use custom processing
JSON文件的don't want to use custom processing
并将其转换为Map,这容易出错并且性能问题。
Please have a look at Jackson data bind docs int the below link: 请查看以下链接中的Jackson数据绑定文档:
map = mapper.readValue(new File("J:/temp/sample.json"), HashMap.class);
returns a Map. 返回一张地图。
Reference: 参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.