3

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 2

4

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);
    }  
Sign up to request clarification or add additional context in comments.

1 Comment

I meant all the rows in a table.
1

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

Or GSON. A better choice IMHO. You are right, it's not a good practice. But so much efficient.
can u tell me how to read and convert all the rows in a table of sqlite to json object??
For Jackson, you need to write json models, fill them and the framework provides method to build the JSON string. If you want use Jackson, start with this. Else you can try with GSON as suggested by Shemsu-Hor or build you own JSON reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.