2016-12-21 4 views
0

私は、サーバーへのJsonArrayRequestからポストを送っwan'tと私はいくつかの答えを見つけたと私はそれをしようと...アンドロイド - 参加JsonArrayRequestボレーStringRequestポスト

が、私はこれは私のコードこのlike this

のようなエラーになりました

HashMap<String, String> params = new HashMap<String, String>(); 

public void JSON_DATA_WEB_CALL() { 
     jsonArrayRequest = new JsonArrayRequest(GET_JSON_DATA_HTTP_URL, new JSONObject(params), 
       new Response.Listener<JSONArray>() { 
        @Override 
        public void onResponse(JSONArray response) { 

         JSON_PARSE_DATA_AFTER_WEBCALL(response); 
        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError error) { 

        } 
       }){ 
      @Override 
      public Map<String, String> getHeaders() throws AuthFailureError { 
       HashMap<String, String> headers = new HashMap<String, String>(); 
       headers.put("CUSTOM_HEADER", "Yahoo"); 
       headers.put("ANOTHER_CUSTOM_HEADER", "Google"); 
       return headers; 
      } 
     }; 
     requestQueue = Volley.newRequestQueue(this); 
     requestQueue.add(jsonArrayRequest); 
    } 

どのように修正するのですか?

+0

この記事を読む:http://stackoverflow.com/questions/24358402/android-volley-post-request-workaround-forあなたのケースで

public class CustomJsonArrayRequest extends JsonRequest<JSONArray> { /** * Creates a new request. * @param method the HTTP method to use * @param url URL to fetch the JSON from * @param jsonRequest A {@link JSONObject} to post with the request. Null is allowed and * indicates no parameters will be posted along with request. * @param listener Listener to receive the JSON response * @param errorListener Error listener, or null to ignore errors. */ public CustomJsonArrayRequest(int method, String url, JSONObject jsonRequest, Response.Listener<JSONArray> listener, Response.ErrorListener errorListener) { super(method, url, (jsonRequest == null) ? null : jsonRequest.toString(), listener, errorListener); } @Override protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) { try { String jsonString = new String(response.data, HttpHeaderParser.parseCharset(response.headers, PROTOCOL_CHARSET)); return Response.success(new JSONArray(jsonString), HttpHeaderParser.parseCacheHeaders(response)); } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JSONException je) { return Response.error(new ParseError(je)); } } } 

実装は次のようなものでなければなりません-jsonarrayrequest?rq = 1 – Stanojkovic

+0

申し訳ありませんが、私の場合はどのように実装するのですか? –

答えて

0

このカスタムクラスを使用します。

HashMap<String, String> params = new HashMap<String, String>(); 

public void JSON_DATA_WEB_CALL() { 
    CustomJsonArrayRequest request = new CustomJsonArrayRequest (Request.Method.POST, GET_JSON_DATA_HTTP_URL, new JSONObject(params), 
      new Response.Listener<JSONArray>() { 
       @Override 
       public void onResponse(JSONArray response) { 

        JSON_PARSE_DATA_AFTER_WEBCALL(response); 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

       } 
      }){ 
     @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      HashMap<String, String> headers = new HashMap<String, String>(); 
      headers.put("CUSTOM_HEADER", "Yahoo"); 
      headers.put("ANOTHER_CUSTOM_HEADER", "Google"); 
      return headers; 
     } 
    }; 
    requestQueue = Volley.newRequestQueue(this); 
    requestQueue.add(request); 
} 
+0

私は 'PROTOCOL_CHARSET'が' com.andoir.volley.toolbox.JsonRequest 'のプライベートアクセスを持っているというエラーがあります。 –

+0

これまでに行ったことを投稿できますか?また、エラーのスタックトレース? – jlively

+0

これはCustomJsonArrayRequest http://pastebin.com/KSFZZB1eであり、これはhttp://pastebin.com/s8rx3YDQ –

関連する問題