I am unable to make a network call using Volley

前端 未结 4 1532
甜味超标
甜味超标 2021-01-24 09:13

When I am making a network call using jsonObject request. I am not receiving any response. I always receive HTTP response for request=<[ ] before my URL. I have tried these l

4条回答
  •  梦毁少年i
    2021-01-24 09:37

    Another Solution using StringRequest to get Json Response

      private void callApi() {
        RequestQueue mrequestQueue;
        StringRequest stringRequest;
        mrequestQueue = Volley.newRequestQueue(this);
        stringRequest = new StringRequest(Request.Method.GET, DATA_URL, new Response.Listener() {
            @Override
            public void onResponse(String response) {
    
                try {
    
                    JSONObject jsonObject = new JSONObject(response);
                    System.out.println("json"+jsonObject);
    
    
                } catch (JSONException e) {
    
                    e.printStackTrace();
                }
    
    
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //Log.i(TAG, "Response: " + error.toString());
    
            }
        });
        mrequestQueue.add(stringRequest);
    
    
    }
    

提交回复
热议问题