Why don't you try:
`
JSONObject object = new JSONObject(); try { object.put("id", id); object.put("startDate", startDate); object.put("endDate", endDate); } catch (JSONException e) { e.printStackTrace(); }`
Then send json object via http message
`
HttpClient hc = new DefaultHttpClient(); String message; HttpPost p = new HttpPost(url); try { message = object.toString(); p.setEntity(new StringEntity(message, "UTF8")); p.setHeader("Content-type", "application/json"); HttpResponse resp = hc.execute(p); if (resp != null) { if (resp.getStatusLine().getStatusCode() == 204) result = true; } Log.d("Status line", "" + resp.getStatusLine().getStatusCode()); } catch (Exception e) { e.printStackTrace(); }`
so if you want to create a JSON object containing all the triplets you get from SQLite db, this will be:
String query = "SELECT *"+ "from "+TABLE_NAME; Cursor c = db.rawQuery(query,new String[]{}); Log.d("query",query); c.moveToFirst(); while(c.moveToNext()){ try { int id = c.getInt(c.getColumnIndex("ID")); String startDate = c.getString(c.getColumnIndex("START_DATE")); String endDate = c.getString(c.getColumnIndex("END_DATE")); object.put("id", id); object.put("startDate", startDate); object.put("endDate", endDate); }}
where ID, START_DATE and END_DATE are the corresponding field names in the database.
I canโt check my code right now, but I believe that it works
source share