Trying to store a JSON array into couchbase using this code in Android, put it is unsuccessful. Please help with how to successfully store it and also how to iteratively receive all data
private void storeLocalData() {
//COUCHBASE IMPLEMENTATION
// Create a manager
manager = null;
try {
manager = new Manager(new AndroidContext(getActivity()), Manager.DEFAULT_OPTIONS);
} catch (IOException e) {
e.printStackTrace();
}
// Create or open the database named 'saved_project_sample'
database = null;
try {
database = manager.getDatabase("saved_project_sample");
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
// Create a new document
document = database.createDocument();
try {
//Cast json String into JSON Array
JSONArray jsonArray= new JSONArray(json);
HashMap<String, Object> properties = new HashMap<>();
for (int k = 0; k < jsonArray.length(); k++) {
JSONObject objJson = jsonArray.getJSONObject(k);
Object id = objJson.getString("id");
Object title = objJson.getString("title");
Object owner_id = objJson.getString("owner_id");
Object description = objJson.getString("description");
Object status = objJson.getString("status");
Object start_time = objJson.getString("start_time");
Object finish_time = objJson.getString("finish_time");
Object created = objJson.getString("created");
Object modified = objJson.getString("modified");
properties.put("id", id);
properties.put("title", title);
properties.put("owner_id", owner_id);
properties.put("description", description);
properties.put("status", status);
properties.put("start_time", start_time);
properties.put("finish_time", finish_time);
properties.put("created", created);
properties.put("modified", modified);
document.putProperties(properties);
Toast.makeText(getActivity(), "Successful Storage", Toast.LENGTH_SHORT).show();
}
} catch (CouchbaseLiteException e) {
e.printStackTrace();
Toast.makeText(getActivity(), "Unsuccessful", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getActivity(), "Unsuccessful", Toast.LENGTH_SHORT).show();
}
}
This is my JSON Array
[
{"id": "1",
"title": "New API",
"owner_id": "dsdssdsd445d",
"description": "Yh A Testin API",
"status": "unactiveAPI",
"start_time": "2017-08-01 14:25:22.060000",
"finish_time": "2017-08-01 14:25:22.060000",
"created": "2017-08-01 14:25:22.060000",
"modified": "2017-08-01 14:25:22.060000"},
{"id": "2",
"title": "New TW Projec API",
"owner_id": "dsdssdsd445d",
"description": "Testin API",
"status": "unactiveAPI",
"start_time": "2017-08-01 14:25:22.060000",
"finish_time": "2017-08-01 14:25:22.060000",
"created": "2017-08-01 14:25:22.060000",
"modified": "2017-08-01 14:25:22.060000"},
{"id": "3",
"title": "Projec API",
"owner_id": "dsdssdsd445d",
"description": "Testin",
"status": "unactiveAPI",
"start_time": "2017-08-01 14:25:22.060000",
"finish_time": "2017-08-01 14:25:22.060000",
"created": "2017-08-01 14:25:22.060000",
"modified": "2017-08-01 14:25:22.060000"},
]