/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.volley.toolbox;

import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;

import org.json.JSONArray;
import org.json.JSONException;

import java.io.UnsupportedEncodingException;

/**
 * A request for retrieving a {@link JSONArray} response body at a given URL.
 */
public class JsonArrayRequest extends JsonRequest<JSONArray> {

    /**
     * Creates a new request.
     * @param url URL to fetch the JSON from
     * @param listener Listener to receive the JSON response
     * @param errorListener Error listener, or null to ignore errors.
     */
    public JsonArrayRequest(String url, Listener<JSONArray> listener, ErrorListener errorListener) {
        super(Method.GET, url, null, listener, errorListener);
    }

    /**
     * Creates a new request.
     * @param method the HTTP method to use
     * @param url URL to fetch the JSON from
     * @param jsonRequest A {@link JSONArray} 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 JsonArrayRequest(int method, String url, JSONArray jsonRequest,
                            Listener<JSONArray> listener, 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));
        }
    }
}

@@ -1054,16 +1054,289 @@
 URL.%0A */
+%0A%0A/*%0A * JsonArrayRequest %E7%BB%A7%E6%89%BF%E8%87%AA JsonRequest%3CJSONArray%3E%0A * %E5%B0%86 JsonRequest%3CT%3E %E7%9A%84%E6%B3%9B%E5%9E%8B T%EF%BC%8C%E8%AE%BE%E7%BD%AE%E4%B8%BA JSONArray%0A *%0A * %E7%94%B1%E4%BA%8E JsonRequest%3CT%3E %E5%8F%AA%E6%98%AF%0A * %E8%A6%81%E6%B1%82 %E8%BF%94%E5%9B%9E%E8%AF%B7%E6%B1%82%E7%BB%93%E6%9E%9C%E6%95%B0%E6%8D%AE%E7%9A%84 %E6%A0%BC%E5%BC%8F ( Response.body ) %E6%8C%87%E5%AE%9A%E4%B8%BA json ( Content-Type%EF%BC%9Aapplication/json; charset=utf-8 )%0A * %E5%86%8D%E5%B0%86 %E8%AF%B7%E6%B1%82%E7%BB%93%E6%9E%9C%E6%95%B0%E6%8D%AE ( Response.body ) %E8%BD%AC%E6%8D%A2%E4%B8%BA utf-8 %E7%9A%84 byte%5B%5D%0A *%0A *%0A */
 %0Apublic 
@@ -1606,32 +1606,72 @@
 errors.%0A     */%0A
+    /*%0A     * Method %E9%BB%98%E8%AE%A4%E4%B8%BA%EF%BC%9AGET %E8%AF%B7%E6%B1%82%0A     */%0A
     public JsonA
@@ -2542,24 +2542,263 @@
 er);%0A    %7D%0A%0A
+    /*%0A     * %E8%A7%A3%E6%9E%90%E8%AF%B7%E6%B1%82%E7%BB%93%E6%9E%9C %EF%BC%88 NetworkResponse %EF%BC%89%0A     * %E5%B0%86 body %E8%BF%94%E5%9B%9E%E7%9A%84 json byte%5B%5D %E8%BD%AC%E6%8D%A2%E4%B8%BA json String%0A     * %E5%86%8D%E5%B0%86 json String %E8%BD%AC%E6%8D%A2%E4%B8%BA JSONArray%0A     *%0A     * 1. %E6%88%90%E5%8A%9F%E8%BD%AC%E4%B8%BA JSONArray %E7%9A%84%E8%AF%9D%EF%BC%8C%E8%B0%83%E7%94%A8 %E8%A7%A3%E6%9E%90%E6%95%B0%E6%8D%AE%E5%9B%9E%E8%B0%83%E6%8E%A5%E5%8F%A3%0A     * 2. %E5%A4%B1%E8%B4%A5%E7%9A%84%E8%AF%9D%EF%BC%8CResponse.error(...) new %E4%B8%80%E4%B8%AA%E5%8F%AA%E6%9C%89 error %E7%9A%84 Response%0A     */%0A
     @Overrid

add JsonArrayRequest comments in volley module