Problema con la sincronizacion de Sqlite con Mysql Tengo el problema que no me guadar en la tabla si lo recibo pero me da error , en el momento de transformarlo a Json
Gracias por ayuda de antemano . (Soy nuevo en esto)
Método que manda la info al servidor
Código Java:
Ver originalpublic void sync (View v ) { // Tag used to cancel the request String tag_string_req = "req_login"; pDialog.setMessage("Logging in..."); pDialog.show(); StringRequest strReq = new StringRequest (Method. POST, AppConfig.URL_SYNC, new Response.Listener<String>() { public void onResponse (String response ) { Log.d("Login Response", "Login Response: " + response.toString()); pDialog.cancel(); String user = config. getUser(); try { JSONObject jObj = new JSONObject(response); boolean error = jObj.getBoolean("error"); // Check for error node in json if (!error) { // user successfully logged in // Create login session int contLogin = objSqlt.getUser(user); if (contLogin == 0) { JSONObject obj = jObj.getJSONObject("user"); Integer id_mysql = obj. getInt("id_mysql"); String user1 = obj. getString("user"); String pass_encrypted = obj. getString("pass_encrypted"); String pass1 = obj. getString("pass"); // Inserting row in users table objSqlt.addUser(id_mysql, user1, pass_encrypted, pass1); } } else { session.setControl_login(false); String errorMsg = jObj. getString("error_msg"); Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show(); } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { public void onErrorResponse(VolleyError error) { Log.e("Sysn Error: ", error.getMessage()); Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show(); pDialog.cancel(); } }) { @Override protected Map <String, String > getParams () { Map <String, String > params = objSqlt. getJSONfromSQLite(); return params; } }; // Adding request to request queue AppController.getInstance().addToRequestQueue(strReq, tag_string_req); }
Mi funcion de la clase sqlite, que hace la consulta a la base de datos de android
Código Java:
Ver originalpublic Map <String, String > getJSONfromSQLite (){ SQLiteDatabase database = this.getWritableDatabase(); int control=0; String selectQuery = "SELECT id_sqlite, user, company, form, checkBox, date FROM chequeo where status = '2' "; Cursor cursor = database. rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { HashMap <String, String > map = new HashMap <String, String >(); map.put("id_sqlite", cursor.getString(0)); map.put("user", cursor.getString(1)); map.put("company", cursor.getString(2)); map.put("form", cursor.getString(3)); map.put("checkBox", cursor.getString(4)); map.put("date", cursor.getString(5)); array.put(control+"",map+""); control++; } while (cursor.moveToNext()); } database.close(); Log.d("map", array.toString()); json.put("json", array.toString()); return json; }
EL error que me muestra
Código Log:
Ver original4-14 14:07:07.938: D/Login Response(1038): Login Response:
04-14 14:07:07.938: D/Login Response(1038): string(819) "{3={date=2015-04-10, checkBox=[[0], [1], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], form=2, user=a, id_sqlite=4, company=2}, 2={date=2015-04-10 20:57:59, checkBox=[[1], [1], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], form=3, user=a, id_sqlite=3, company=1}, 1={date=2015-04-10 20:50:05, checkBox=[[0], [0], [0], [0], [1], [0], [0], [0], [0], [0], [0], [0]], form=1, user=a, id_sqlite=2, company=1}, 0={date=2015-04-10 20:33:17, checkBox=[[0], [1], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], form=2, user=a, id_sqlite=1, company=1}, 5={date=2015-04-13, checkBox=[[0], [1], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], form=2, user=a, id_sqlite=6, company=3}, 4={date=2015-04-13, checkBox=[[1], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [0]], form=1, user=a, id_sqlite=5, company=3}}"
04-14 14:07:07.938: D/Login Response(1038): []$id_sqlite,$user,$company,$form,$checkbox,$date)
04-14 14:07:07.948: W/System.err(1038): org.json.JSONException: Value string(819) of type java.lang.String cannot be converted to JSONObject
04-14 14:07:07.968: W/System.err(1038): at org.json.JSON.typeMismatch(JSON.java:111)
04-14 14:07:07.968: W/System.err(1038): at org.json.JSONObject.<init>(JSONObject.java:158)
04-14 14:07:07.968: W/System.err(1038): at org.json.JSONObject.<init>(JSONObject.java:171)
04-14 14:07:07.988: W/System.err(1038): at com.example.php_mysql_sqlite.MainActivity$1.onResponse(MainActivity.java:131)
04-14 14:07:07.988: W/System.err(1038): at com.example.php_mysql_sqlite.MainActivity$1.onResponse(MainActivity.java:1)
04-14 14:07:07.997: W/System.err(1038): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
04-14 14:07:08.018: W/System.err(1038): at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
04-14 14:07:08.048: W/System.err(1038): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
04-14 14:07:08.048: W/System.err(1038): at android.os.Handler.handleCallback(Handler.java:725)
04-14 14:07:08.048: W/System.err(1038): at android.os.Handler.dispatchMessage(Handler.java:92)
04-14 14:07:08.057: W/System.err(1038): at android.os.Looper.loop(Looper.java:137)
04-14 14:07:08.057: W/System.err(1038): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-14 14:07:08.057: W/System.err(1038): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 14:07:08.068: W/System.err(1038): at java.lang.reflect.Method.invoke(Method.java:511)
04-14 14:07:08.068: W/System.err(1038): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-14 14:07:08.068: W/System.err(1038): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-14 14:07:08.068: W/System.err(1038): at dalvik.system.NativeStart.main(Native Method)
Pagina php del servidor
Código PHP:
Ver original<?php include_once 'include/DB_Functions.php'; //Create Object for DB_Functions clas $db = new DB_Functions(); //Get JSON posted by Android Application $json = $_POST["json"]; $db->storeTemporal($json); //Remove Slashes } //Decode JSON into an Array //Util arrays to create response JSON //Loop through an Array and insert data read from JSON into MySQL DB for ($i = 0; $i < count($data); $i++) { //Store User into MySQL DB $res = $db->guardar_chequeo($data[$i]->id_sqlite, $data[$i]->user, $data[$i]->company, $data[$i]->form, $data[$i]->checkbox, $data[$i]->date); //Based on inserttion, create JSON response if ($res) { $b["id"] = $data[$i]->userId; $b["status"] = 'yes'; } else { $b["id"] = $data[$i]->userId; $b["status"] = 'no'; } } //Post JSON response back to Android Application ?>
Como pueden ver, el servidor si lo recibe y lo imprime, pero despues da el error |