我是NoSQL數據庫的新手。我想將以下JSON數據保存到CouchBase Lite中。有人可以指導我以最好的方式來做到這一點嗎?如何將數據插入到JSON格式的couchbase lite android
{"widget": {
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity/100) * 90;"
}
}}
我試着用下面的代碼來做到這一點。
public void insertSample(String widget,String control,ArrayList<eModel> details){
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("control", control);
properties.put("details", details);
Document document = database.getDocument(widget);
try {
document.putProperties(properties);
} catch (CouchbaseLiteException e) {
Log.e("", "Cannot save document", e);
}
}
但是這段代碼每次都會創建一個新的id。我想多次插入相同的窗口小部件值。
這是運行時數據,而不是我想要逐個插入的靜態數據。
例如,發出的Widget圖如下:
{"widget": {
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
}
然後我要追加下的「窗口」字段以下字段:
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
}
,如果你想使用相同的部件值多次,您可以更新 –
@pushpendrachauhan如果我更新,然後怎麼樣舊數據? –