This is my activity.java.
Код: Выделить всё
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL, null, new Response.Listener < JSONObject > () { @Override public void onResponse(JSONObject response) { Log.d("volleytracker", response.toString()); try { String message = response.getString("message"); boolean successful = response.getBoolean("result"); String userId = response.getString("user_id"); if (successful) { //save userId on shared memory PrefManager prefManager = new PrefManager(context); prefManager.SaveUSerID(Integer.valueOf(userId)); // intent NextActivity Intent intent = new Intent(Register.this, VerificationPage.class); startActivity(intent); } else { status.setText(message); status.setTextColor(Color.parseColor("#FF0000")); } } catch (JSONException e) { Log.d("checkError", e.toString()); e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(Register.this, error.toString().trim(), Toast.LENGTH_SHORT).show(); Log.d("errorcheck", error.toString()); regBtn.setEnabled(true); } }) { public byte[] getBody() { JSONObject jsonParams = new JSONObject(); try { jsonParams.put("name", name); jsonParams.put("PhoneNumber", phone); jsonParams.put("deviceId", deviceId); //jsonParams.put("DeviceIP", getiP); //Log.d("jsonPara",jsonParams.toString()); } catch (JSONException e) { e.printStackTrace(); } return jsonParams.toString().getBytes(); } @Override public String getBodyContentType() { return "application/json"; } @Override public Map < String, String > getHeaders() throws AuthFailureError { Map < String, String > headers = new HashMap < > (); return headers; } }; RequestQueue requestQueue = Volley.newRequestQueue(Register.this); requestQueue.add(jsonObjectRequest);
Код: Выделить всё
com.android.volley.ParseError: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
Источник: https://stackoverflow.com/questions/781 ... f-type-jav