0

I wrote this method:

public JSONObject getJSONFromUrl(String url, final Map<String, String> params) {
    StringRequest post = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        /**
         *
         * @param response
         */
        @Override
        public void onResponse(String response) {
            try {
                JSONObject jsonResponse = new JSONObject(response);

                Log.v("JSONParser", "response: " + jsonResponse.toString());
            } catch(JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        /**
         *
         * @param error
         */
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }) {
        /**
         *
         * @return
         * @throws AuthFailureError
         */
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            return params;
        }
    };

    Volley.newRequestQueue(this.context).add(post);

    return null;
}

I need to return that JSONObject that i create in onResponse but i cant figure out how to do it. Is there any way to return the JSONObject? I also cant assign the JSONObject to a final variable inside the method and return it.

Mulgard
  • 9,877
  • 34
  • 129
  • 232

1 Answers1

4

If the shown code is indeed working (up to the log jsonResponse.toString()), you may do as shown here

Community
  • 1
  • 1
Bonatti
  • 2,778
  • 5
  • 23
  • 42