0

以下は私のjsonコードですが、jsonファイルから単一の値のみを返します.jsonファイルから単一の金曜日のみを取得していますが、実際にはjsonファイルには4つの金曜日があります金曜日のすべての値を取得するにはどうすればよいですか? コードを実行すると、ListView今週の金曜日の値 "dish_name":"Hamburger" のみが表示され、金曜日の 4 つの値すべてを取得する方法

  {
      "status": 1,
      "data": [{
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "Mandarin Chicken Rice Bowl",
          "dish_id": "210",
          "day": "Fri",
          "Schedule": "weekly"
      }, {
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "Chicken Burger",
          "dish_id": "206",
          "day": "Fri",
          "Schedule": "weekly"
      }, {
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "Garden Fresh Salad",
          "dish_id": "211",
          "day": "Fri",
          "Schedule": "weekly"
      },


      {
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "A Test",
          "dish_id": "213",
          "day": "Mon",
          "Schedule": "weekly"
      }, {
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "Hamburger",
          "dish_id": "56",
          "day": "Fri",
          "Schedule": "weekly"
      }, {
          "school_name": "LittleStar ",
          "calendar_id": "1",
          "menu_title": "Atypical Menu",
          "dish_name": "Tofu Caesar Salad w\/ Roll",
          "dish_id": "149",
          "day": "Fri",
          "Schedule": "weekly"
      }]
  }

HelloworldActivity.java

  public class HelloworldActivity extends Activity {
int count = 0;
Date date1;
Date date2;
String id;
String title;
String byweekdate;
int IOConnect = 0;
String mVal2;
String mVal3;
String mVal9;
String SelectMenuAPI;
String url;
String URL;
String URL2, URL3, URL4;
String menu_title;
JSONArray school;
ListView listCategory;
String status;
String message;
String _response;
String SelectMenuAPI2;
TextView menu_nametxt;
thirdstepAdapter cla;
static ArrayList<Long> Category_ID = new ArrayList<Long>();
static ArrayList<String> school_name = new ArrayList<String>();
static ArrayList<String> menu_name = new ArrayList<String>();

static ArrayList<String> dish_name = new ArrayList<String>();
static ArrayList<String> dish_ID = new ArrayList<String>();
static ArrayList<String> day = new ArrayList<String>();

static ArrayList<Long> Vacation_ID = new ArrayList<Long>();
static ArrayList<String> Vacation_name = new ArrayList<String>();
static ArrayList<String> Vacation_Date = new ArrayList<String>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    listCategory = (ListView) findViewById(R.id.thirdscreenlist);
    menu_nametxt = (TextView) findViewById(R.id.menu_name);
    cla = new thirdstepAdapter(HelloworldActivity.this);
    listCategory.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int position, long arg3) {
        }
    });

    new getDataTask().execute();
}

void clearData() {
    Category_ID.clear();
    school_name.clear();
    menu_name.clear();
    dish_name.clear();
    dish_ID.clear();
    day.clear();
    Vacation_ID.clear();
    Vacation_name.clear();
    Vacation_Date.clear();
}

public class getDataTask extends AsyncTask<Void, Void, Void> {
    getDataTask() {
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        parseJSONData();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub

        if ((Category_ID.size() > 0) || IOConnect == 0) {

            listCategory.setAdapter(cla);
            menu_nametxt.setText(mVal2);
            // cla.notifyDataSetChanged();
        }
    }
}

public void parseJSONData() {
    clearData();
    SelectMenuAPI = "http://198.57.208.46/~school/index.php/api/index/getMenuBySchool?sid=147&lid=1";
    URL = SelectMenuAPI;
    URL2 = URL.replace(" ", "%20");

    try {
        Log.i("url", "" + URL2);
        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams
                .setConnectionTimeout(client.getParams(), 15000);
        HttpConnectionParams.setSoTimeout(client.getParams(), 15000);
        HttpUriRequest request = new HttpGet(URL2);
        HttpResponse response = client.execute(request);

        HttpEntity resEntity = response.getEntity();
        _response = EntityUtils.toString(resEntity);

        JSONObject json2 = new JSONObject(_response);

        status = json2.getString("status");
        if (status.equals("1")) {

            JSONArray school = json2.getJSONArray("data");

            for (int i = 0; i < school.length(); i++) {
                JSONObject object = school.getJSONObject(i);
                if (count == 1) {
                    count = 0;
                    break;
                } else

                if (object.getString("Schedule").equals("weekly")) {
                    if (object.getString("day").equals("Fri")) {
                        Category_ID.add((long) i);
                        school_name.add(object.getString("school_name"));
                        dish_ID.add(object.getString("dish_id"));
                        dish_name.add(object.getString("dish_name"));
                        menu_name.add(object.getString("menu_title"));
                        day.add(object.getString("day"));
                        count = count + 1;
                        String[] mVal = new String[school.length()];
                        for (int k = 0; k < school.length(); k++) {
                            mVal[k] = school.getJSONObject(k).getString(
                                    "menu_title");
                            message = "weekly";
                            mVal2 = mVal[0];
                            // count = count + 1;
                        }

                    } else {
                    }
                } else if (object.getString("Schedule").equals("biweekly")) {

                    if (object.getString("day").equals(byweekdate)) {
                        Category_ID.add((long) i);
                        school_name.add(object.getString("school_name"));
                        menu_name.add(object.getString("menu_title"));
                        day.add(object.getString("day"));
                        String[] mVal = new String[school.length()];
                        for (int k = 0; k < school.length(); k++) {
                            mVal[k] = school.getJSONObject(k).getString(
                                    "menu_title");

                        }
                        message = "weekly";
                        mVal2 = mVal[0];

                        dish_name.add(object.getString("dish_name"));

                        count = count + 1;

                    } else {
                    }
                } else {
                }
            }
        } else {
        }
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        IOConnect = 1;
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}
4

1 に答える 1