I have an app that gets all the data from the sqlite database and converts it into JSON, but I was wondering how would I be able to do it if I only want to get the data of specific columns?
This is the code I use to get all the data from the SQLite databse and convert it to JSON:
Cursor data = db.getCartItems(); orderNameArray = new JSONArray(); data.moveToFirst(); while(data.isAfterLast() == false) { int totalColumn = data.getColumnCount(); orderNameObject = new JSONObject(); for (int i = 0; i < totalColumn; i++) { try { orderNameObject.put(data.getColumnName(i), data.getString(i)); } catch (JSONException e) { e.printStackTrace(); } } orderNameArray.put(orderNameObject); data.moveToNext(); } data.close(); Thanks in advance for all the insights or help in advance! :D
continueto skip columns you selected if you don't wish to write a custom SELECT statement.