I am trying to send SQLite data with an MySQL online server, but to no avail. Naturally, I ran to Google and was lucky to find this . Apparently, it should work, and it works, but I am not receiving data on my server.
I know that this question is asked here and here , but I could not fix it using the above suggestions.
Here is what I have tried. Here's how I convert SQLite data to JSON using GSON:
public String composeJSONfromSQLite() { ArrayList<HashMap<String, String>> offlineList; offlineList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM offlineTable "; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { HashMap<String, String> map = new HashMap<String, String>(); map.put("zip", cursor.getString(1)); map.put("phone", cursor.getString(2)); map.put("uid", cursor.getString(3)); offlineList.add(map); } while (cursor.moveToNext()); } database.close(); Gson gson = new GsonBuilder().create();
And this is how I send it to my server:
public void syncSQLiteMySQLDB() { AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put("offline",loadCheckoutDB.composeJSONfromSQLite()); Log.d("offline data log", loadCheckoutDB.composeJSONfromSQLite()); client.addHeader("session_id", getapikey()); client.addHeader("Content-Type", "application/json"); client.post("http://example.com/offline/api", params, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String s = new String(responseBody); Log.d("response to sync", s); try { JSONObject obj = new JSONObject(s); if (obj.getBoolean("success")) { String success = obj.getString("message");
And when I register what JASON looks like with Android, I get this format:
[{ "zip": "325, "phone": "78291849", "uid": "14538177211" }]
But on my server, I still get an empty array. What am I doing wrong?
Here's what my request format should look like:
{ "offline":[ { "zip": "325, "phone": "78291849", "uid": "14538177211" } ] }
This is how I get the request:
public function massData() // offline sync { $input = Input::all(); return $input;