Android 如何使用截击返回JSONObject

Android 如何使用截击返回JSONObject,android,android-volley,Android,Android Volley,我写了这个方法: public JSONObject getJSONFromUrl(String url, final Map<String, String> params) { StringRequest post = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() { /** * * @param resp

我写了这个方法:

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;
}
publicJSONObject getJSONFromUrl(字符串url,最终映射参数){
StringRequest post=新的StringRequest(Request.Method.post,url,new Response.Listener()){
/**
*
*@param响应
*/
@凌驾
公共void onResponse(字符串响应){
试一试{
JSONObject jsonResponse=新的JSONObject(响应);
Log.v(“JSONParser”,“response:+jsonResponse.toString());
}捕获(JSONException e){
e、 printStackTrace();
}
}
},new Response.ErrorListener(){
/**
*
*@param错误
*/
@凌驾
公共无效onErrorResponse(截击错误){
错误。printStackTrace();
}
}) {
/**
*
*@返回
*@AuthFailureError
*/
@凌驾
受保护的映射getParams()引发AuthFailureError{
返回参数;
}
};
newRequestQueue(this.context).add(post);
返回null;
}

我需要返回我在
onResponse
中创建的
JSONObject
,但我不知道怎么做。有没有办法返回JSONObject?我也无法将JSONObject分配给方法中的最后一个变量并返回它。

如果显示的代码确实在工作(直到日志
jsonResponse.toString()
),如果显示的代码确实在工作(直到日志
jsonResponse.toString()