I need to create JSON OBJECT from sqlite database. And further I want to store that JSON OBJECT in my server. And I want to convert an entire table in my sqlite database to JSON object so that my data doesn't occupy much space in my server.Is this possible?? If so, can someone help me by providing proper resources for doing this?
2 Answers
Create JSON OBJECT from sqlite database-I've tried something like this.What do u mean by converting entire table in my sqlite database to Json object???
JSONObject jsonObject = new JSONObject();
ArrayList<DrugDetails> drugDetails = DataInterface
.getSelectedDrugDetails();//this should be ur db query which returns the arraylist
if (drugDetails != null && drugDetails.size() > 0) {
JSONArray array = new JSONArray();
for (DrugDetails selectedDrugDetails : drugDetails) {
JSONObject json = new JSONObject();
json.put(APPOINTMENT_ID, ""+"selectedDrugDetails.getAppoinmentID()");
json.put(DOCUMENT_ID, ""+selectedDrugDetails.getId());
array.put(json);
}
jsonObject.put(COLLATERAL_LIST, array);
}
1 Comment
gamma
I meant all the rows in a table.
JSON "object" is no more than a String so you can store them in a DB as a String.
Nevertheless I had never seen this and I don't think it's a good practice. If you are looking for a simple and efficient JSON parser/reader, look at Jackson.
Maybe I misunderstood you question.
3 Comments
shemsu
Or GSON. A better choice IMHO. You are right, it's not a good practice. But so much efficient.
gamma
can u tell me how to read and convert all the rows in a table of sqlite to json object??