无法将Json对象发送到android中的服务器

时间:2019-06-18 11:18:59

标签: android android-volley

我知道这个问题已经被问到了,但仍然对我不起作用。我无法将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";
   }

0 个答案:

没有答案