dpv21589 2015-03-17 12:17
浏览 170
已采纳

带参数的jsonarray请求

I have a php webservice that returns a json array using json_encode(array("moviemakers"=>$rows)). I need to make the json array request from android with parameters.

I saw this:

public JsonArrayRequest(int method, String url, JSONObject jsonRequest,
        Listener<JSONArray> listener, ErrorListener errorListener) {
        super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), 
        listener, errorListener);
}

When I use it in my code, it generates an error.
Could anyone guide me where to put the above snippet in my code?

  • 写回答

1条回答 默认 最新

  • dongzhong6675 2015-03-17 13:00
    关注

    Here an example of a JsonObjectRequest:

     private void volleyRequest(String url){
            final JsonObjectRequest request = new JsonObjectRequest(url, null, new Response.Listener<JSONObject>(){
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        Log.i(LOG_FLAG, response.toString(4));
                        //parseJSON
                    }catch (JSONException e){
                        //handle exception
                    }
                }
            },new Response.ErrorListener(){
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    //handle error
                }
            });
            //adding request into the queue
            ApplicationClass.getInstance().addToRequestQueue(request,"someTag");
        }
    

    here you can find a really nice tutorial about volley: Asynchronous HTTP Requests in Android Using Volley

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?