JSONデータの配列を取得し、表示してアクセスしようとしていますが、表示しようとすると、JSONデータの配列の最後の行しか表示されません。json1.get(2)(ここでのjson1はJSONObjectを含むJSONArrayです)配列が範囲外のエラーになります。何が間違っているのか、JSONを取得する方法を教えてください。以下は、この質問に関連するコードです。
ありがとうございました。
Freebies.javaクラスからUserFunctions.javaクラスのgetAllFreebies関数を呼び出すim
UserFunctions uf = new UserFunctions();
JSONObject json = uf.getAllFreebies();
以下は、UserFunctions.javaクラスのgetAllFreebies()関数のコードです。
public JSONObject getAllFreebies(){
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("tag", getAllFreebies_tag));
    JSONObject json  = jsonParser.getJSONFromUrl(getAllFreebiesURL,params);
    JSONArray json1 = new JSONArray();
    json1.put(json);
    try {
        System.out.println(json1.get(2));
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return json;
}
以下は、DB_Functions.phpクラスのgetFreebies()関数を呼び出すindex.phpクラスのコードです。
else if($tag = 'getAllFreebies'){
                $username = "";
                $catagory = "";
                $subcatagory = "";
                $title = "";
                $condition = "";
                $description = "";
                $address = "";
                $city = "";
                $state = "";
                $country = "";
                $zipcode = "";
                $posted_on= "";
                    $getAllFreebies = $db->getFreebies($username,$catagory,$subcatagory,$title,$condition,$description,$address,$city,$state,$country,$zipcode,$posted_on);
            $data = array();
            while($row = mysql_fetch_assoc($getAllFreebies)) {
            $response["success"] = 1;
            $data[] = array(
            $response["getAllFreebies"]["username"] = $row["username"],
            $response["getAllFreebies"]["catagory"] = $row["catagory"],
            $response["getAllFreebies"]["subcatagory"] = $row["subcatagory"],
            $response["getAllFreebies"]["title"] = $row["title"],
            $response["getAllFreebies"]["item_condition"] = $row["item_condition"],
            $response["getAllFreebies"]["description"] = $row["description"],
            $response["getAllFreebies"]["address"] = $row["address"],
            $response["getAllFreebies"]["city"] =  $row["city"],
            $response["getAllFreebies"]["state"] = $row["state"],
            $response["getAllFreebies"]["country"] = $row["country"],
            $response["getAllFreebies"]["zipcode"] = $row["zipcode"],
            $response["getAllFreebies"]["posted_on"] = $row["posted_on"]);}
            echo json_encode($response);
                    }// end of getAllFreebies tag
以下は、DB_Functions.phpのgetFreebies()関数のコードです。
public function getFreebies(){
$result = mysql_query("SELECT * FROM freebie") or die(mysql_error());
return($result);
}
更新:JSONArrayを解析するためにJSONParserクラスに以下を追加しましたpublic JSONArray getJSONArrayFromUrl(String url、List params){
    // Making HTTP request
    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "n");
        }
        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
        jarray.put(jObj);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    // return JSON String
    return jarray;
}
そして、getAllFreebie()を変更してJSONArrayを取得しました
public JSONArray getAllFreebies() {
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("tag", getAllFreebies_tag));
    JSONArray json = jsonParser.getJSONArrayFromUrl(getAllFreebiesURL,
            params);
    return json;
}
それでも、すべての行ではなく単一の行しか取得できません。誰かが私が間違っていることを教えてもらえますか。ありがとう:(