Невозможно отправить объект Json на сервер в Android - PullRequest
0 голосов
/ 18 июня 2019

Я знаю, что этот вопрос уже задан, но все же он не работал для меня.Я не могу отправить объект Json на сервер.Я не получаю никакого ответа от сервера.Какую ошибку я сделал здесь.Если я допустил глупую ошибку, пожалуйста, не отмечайте как дубликат и не блокируйте мой аккаунт.Я абсолютно новичок в программировании.Я приложил решение, данное переполнением Satck. seethis

    JsonObject response = new JsonObject();
                response.add("Description", a1 );/*a1 is Json array of 
         multiple values*/
                response.add("Amount", a2 );/*a2 is Json array of 
         multiple values*/
                System.out.println("Json:"+response);/*Both the list is saved inside this Json object*/

                Map<String,String> hm = new HashMap();
                hm.put("Values",String.valueOf(response));/*Trying to pass the json object to server respose is the Json object*/

                 CustomRequest req = new 
      CustomRequest(Request.Method.POST,ip,hm,
      this.createRequestSuccessListener(),       
      this.createRequestErrorListener()); 

                Mysingleton.getInstance(this).addTorequestque(req);/*This 
        is a singleton class*/
   public Response.Listener<JSONObject> createRequestSuccessListener(){
    return new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            AlertDialog.Builder al = new AlertDialog.Builder(Database.this)
                    .setTitle("Message")
                    .setMessage("Sent")
                    .setPositiveButton("OK",null);
            AlertDialog al1 = al.create();
            al.show();
        }
    };
}

public Response.ErrorListener createRequestErrorListener(){
    return new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            AlertDialog.Builder al = new AlertDialog.Builder(Database.this)
                    .setTitle("Error")
                    .setMessage("Something went wrong")
                    .setPositiveButton("OK",null);
            AlertDialog al1 = al.create();
            al.show();
        }
    };
}

 [CustomRequet][1]

My php source code is here
 if(!empty($_POST['Values']){
      $all_arraylist = json_decode(Values,true);
       $ result = print_r($all_arraylist,true);
       echo $result;
    }
     else{
    echo "Empty";
   }
...