コード例 #1
0
    @Override
    protected String doInBackground(String... strings) {
      JsonParser jsonParser = new JsonParser(GamePlayStrategyActivity.this);

      String url = Const.GET_ACTIVE_USERS;
      String jsonString = jsonParser.getJSONFromUrl(url);

      // Log.e("jsonStringurl", url);

      try {
        JSONObject jsonObject = new JSONObject(jsonString);

        if (jsonObject != null) {
          result = jsonObject.getInt(Const.KEY_RESULT);

          activeUsers = jsonObject.getString(Const.KEY_ACTIVE_USER);
        } else {
          msg = jsonObject.getString(Const.KEY_MSG);
        }
      } catch (NullPointerException e) {
        e.printStackTrace();
      } catch (JSONException e) {
        e.printStackTrace();
      }

      return null;
    }
コード例 #2
0
    @Override
    protected String doInBackground(String... strings) {
      try {

        JsonParser jsonParser = new JsonParser(GamePlayStrategyActivity.this);

        String url =
            Const.GET_ACTIVE_GAME_DETAIL + "?" + Const.TAG_TEAMID + "=" + pollsPref.getTeamId();

        //  Log.e("url", url);
        String jsonString = jsonParser.getJSONFromUrl(url);

        JSONObject jsonObject = new JSONObject(jsonString);

        if (jsonObject != null) {

          result = 1;

          JSONArray jsonArrayPolLData = jsonObject.getJSONArray(Const.KEY_POLL_DATA);

          arrayListPollData = new ArrayList<PollData>();

          hashMapPollOptions = new HashMap<Integer, ArrayList<PollOptions>>();

          for (int i = 0; i < jsonArrayPolLData.length(); i++) {

            JSONObject jsonObj = jsonArrayPolLData.getJSONObject(i);
            int poll_id = jsonObj.getInt(Const.KEY_POLL_ID);
            if (poll_id == 8) {
              ignorePos = i;
            }

            String poll_name = jsonObj.getString(Const.KEY_POLL_NAME);
            String poll_start_time = jsonObj.getString(Const.KEY_START_TIME);
            String poll_end_time = jsonObj.getString(Const.KEY_END_TIME);
            String poll_duration = jsonObj.getString(Const.KEY_POLL_DURATION);

            String maxValue = jsonObj.getString(Const.KEY_MAX);

            String maxId = jsonObj.getString(Const.KEY_MAX_ID);

            PollData pollData =
                new PollData(
                    poll_id,
                    poll_name,
                    poll_end_time,
                    poll_start_time,
                    poll_duration,
                    maxId,
                    maxValue);

            arrayListPollData.add(pollData);

            JSONArray jsonArrayPollOptions = jsonObj.getJSONArray(Const.KEY_POLL_OPTION);

            ArrayList<PollOptions> arrayListPollOpt = new ArrayList<PollOptions>();

            if (jsonArrayPollOptions.length() != 0) {

              for (int j = 0; j < jsonArrayPollOptions.length(); j++) {

                JSONObject jsonObjOpt = jsonArrayPollOptions.getJSONObject(j);

                //   Log.e("poll", jsonObjOpt.toString());

                String pollId = jsonObjOpt.getString(Const.KEY_POLL_ID);

                String pollName = jsonObjOpt.getString(Const.KEY_POLL_NAME);

                PollOptions pollOptions = new PollOptions(pollId, pollName);

                arrayListPollOpt.add(pollOptions);
              }
            }
            hashMapPollOptions.put(poll_id, arrayListPollOpt);
          }
        } else result = 0;

      } catch (NullPointerException ex) {
        ex.printStackTrace();
      } catch (JSONException e) {
        e.printStackTrace();
      }

      return null;
    }