我正在使用的是从Orient db(服务器)获取数据容器并将其存储在本地方向数据库中,然后在程序的后期使用它。
我有以下jsonObject,它是从服务器方面db:
获得的{
"@type": "d",
"@rid": "#95:0",
"@version": 3,
"@class": "demo1_OnlineShopping",
"product": [
{
"@type": "d",
"@rid": "#97:0",
"@version": 3,
"@class": "demo1_MobilePhone",
"operatingSystem": "Android",
"condition": "",
"minPrice": "100",
"maxPrice": "500",
"keyword": "Galaxy S5",
"brand": "Samsung"
},
{
"@type": "d",
"@rid": "#97:3",
"@version": 1,
"@class": "demo1_MobilePhone",
"operatingSystem": "Android",
"condition": null,
"minPrice": "5",
"maxPrice": "300",
"keyword": "M8",
"brand": "HTC"
}
],
"user": {
"@type": "d",
"@rid": "#100:0",
"@version": 1,
"@class": "demo1_User",
"password": "jamesgillespy@suremail.info",
"email": "1qaz2wsx@"
},
"maxAllowance": "350",
"cart": null,
"lookingFor": "Mobile Phone",
"@fieldTypes": "product=z"
}
我使用下面的代码将其转换为hashmap,以将其存储在本地db:
中Map<String, Object> map = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
map = mapper.readValue(jsonString, new TypeReference<HashMap<String, Object>>(){});
然后使用以下代码将其存储到本地东方数据库中:
ODocument doc = new ODocument("Person");
for(Entry<String, Object> entry : hashmap.entrySet()){
doc.field( entry.getKey(), entry.getValue());
}
doc.save();
我的第一个问题是,它不允许存储以@ like&#34; @ type&#34;,&#34; @ class&#34;它会引发异常。当我删除它们时它会起作用。然后出现另一个问题,那些没有在本地数据库中链接。它存储为一个数据容器,其中必须存在与多个数据容器的链接。我认为这是因为&#34; @ class&#34;不在那里。并且在插入时手动创建数据库名称(Person)似乎是错误的。任何链接或代码都会有所帮助。提前谢谢。