Example usage for org.json JSONObject optBoolean

List of usage examples for org.json JSONObject optBoolean

Introduction

In this page you can find the example usage for org.json JSONObject optBoolean.

Prototype

public boolean optBoolean(String key) 

Source Link

Document

Get an optional boolean associated with a key.

Usage

From source file:com.aniruddhc.acemusic.player.GMusicHelpers.WebClientPlaylistsSchema.java

@Override
public WebClientPlaylistsSchema fromJsonObject(JSONObject jsonObject) {
    if (jsonObject != null) {
        mTitle = jsonObject.optString("title", null);
        mPlaylistId = jsonObject.optString("playlistId", null);
        mRequestTime = jsonObject.optLong("requestTime");
        mContinuationToken = jsonObject.optString("continuationToken", null);
        mDifferentialUpdate = jsonObject.optBoolean("differentialUpdate");
        mContinuation = jsonObject.optBoolean("continuation");

        JSONArray songsArray = jsonObject.optJSONArray("playlist");
        mPlaylist = fromJsonArray(songsArray);
    }/*from w  w w  . j a  va2 s.  co m*/

    //This method returns itself to support chaining.
    return this;
}

From source file:com.aniruddhc.acemusic.player.GMusicHelpers.AddPlaylistResponse.java

@Override
public AddPlaylistResponse fromJsonObject(JSONObject jsonObject) {
    if (jsonObject != null) {
        mId = jsonObject.optString("id", null);
        mTitle = jsonObject.optString("title", null);
        mSuccess = jsonObject.optBoolean("success");
    }//  w ww.jav  a 2s .  co m

    // return this object to allow chaining
    return this;
}

From source file:com.aniruddhc.acemusic.player.GMusicHelpers.MobileClientPlaylistsSchema.java

@Override
public MobileClientPlaylistsSchema fromJsonObject(JSONObject jsonObject) {
    if (jsonObject != null) {
        mKind = jsonObject.optString("kind", null);
        mPlaylistId = jsonObject.optString("id", null);
        mCreationTimestamp = jsonObject.optString("creationTimestamp");
        mLastModifiedTimestamp = jsonObject.optString("lastModifiedTimestamp", null);
        mRecentTimestamp = jsonObject.optString("recentTimestamp");
        mDeleted = jsonObject.optBoolean("deleted");
        mName = jsonObject.optString("name");
        mType = jsonObject.optString("type");
        mShareToken = jsonObject.optString("shareToken");
        mOwnerName = jsonObject.optString("ownerName");
        mOwnerProfilePhotoUrl = jsonObject.optString("ownerProfilePhotoUrl");
        mAccessControlled = jsonObject.optBoolean("accessControlled");
    }/*from   w  ww. j a v  a 2 s.  com*/

    //This method returns itself to support chaining.
    return this;
}

From source file:com.jelly.music.player.GMusicHelpers.WebClientSongsSchema.java

@Override
public WebClientSongsSchema fromJsonObject(JSONObject jsonObject) {

    if (jsonObject != null) {
        mTotalTracks = jsonObject.optInt("totalTracks");
        mSubjectToCuration = jsonObject.optBoolean("subjectToCuration");
        mName = jsonObject.optString("name", null);
        mTotalDiscs = jsonObject.optInt("totalDiscs");
        mTitleNorm = jsonObject.optString("titleNorm", null);
        mAlbumNorm = jsonObject.optString("albumNorm", null);
        mTrack = jsonObject.optInt("track");
        mAlbumArtUrl = jsonObject.optString("albumArtUrl", null);
        mUrl = jsonObject.optString("url", null);
        mCreationDate = jsonObject.optLong("creationDate");
        mAlbumArtistNorm = jsonObject.optString("albumArtistNorm", null);
        mArtistNorm = jsonObject.optString("artistNorm", null);
        mLastPlayed = jsonObject.optLong("lastPlayed");
        mMatchedId = jsonObject.optString("matchedId", null);
        mType = jsonObject.optInt("type");
        mDisc = jsonObject.optInt("disc");
        mGenre = jsonObject.optString("genre", null);
        mBeatsPerMinute = jsonObject.optInt("beatsPerMinute");
        mAlbum = jsonObject.optString("album", null);
        mId = jsonObject.optString("id", null);
        mComposer = jsonObject.optString("composer", null);
        mTitle = jsonObject.optString("title", null);
        mAlbumArtist = jsonObject.optString("albumArtist", null);
        mYear = jsonObject.optInt("year");
        mArtist = jsonObject.optString("artist", null);
        mDurationMillis = jsonObject.optLong("durationMillis");
        mIsDeleted = jsonObject.optBoolean("deleted");
        mPlayCount = jsonObject.optInt("playCount");
        mRating = jsonObject.optString("rating", null);
        mComment = jsonObject.optString("comment", null);
        mPlaylistEntryId = jsonObject.optString("playlistEntryId");
    }/*from   ww w . ja v a2  s .  c om*/

    //This method returns itself to support chaining.
    return this;
}

From source file:com.google.android.apps.muzei.api.internal.SourceState.java

public void readJson(JSONObject jsonObject) throws JSONException {
    JSONObject artworkJsonObject = jsonObject.optJSONObject("currentArtwork");
    if (artworkJsonObject != null) {
        mCurrentArtwork = Artwork.fromJson(artworkJsonObject);
    }//from   www . j ava  2 s  . c  om
    mDescription = jsonObject.optString("description");
    mWantsNetworkAvailable = jsonObject.optBoolean("wantsNetworkAvailable");
    mUserCommands.clear();
    JSONArray commandsSerialized = jsonObject.optJSONArray("userCommands");
    if (commandsSerialized != null && commandsSerialized.length() > 0) {
        int length = commandsSerialized.length();
        for (int i = 0; i < length; i++) {
            mUserCommands.add(UserCommand.deserialize(commandsSerialized.optString(i)));
        }
    }
}

From source file:io.teak.sdk.Session.java

private void identifyUser() {
    final Session _this = this;

    new Thread(new Runnable() {
        public void run() {
            synchronized (_this.stateMutex) {
                HashMap<String, Object> payload = new HashMap<>();

                if (_this.state == State.UserIdentified) {
                    payload.put("do_not_track_event", Boolean.TRUE);
                }//from w  w  w .  j  a va  2  s  .co m

                TimeZone tz = TimeZone.getDefault();
                long rawTz = tz.getRawOffset();
                if (tz.inDaylightTime(new Date())) {
                    rawTz += tz.getDSTSavings();
                }
                long minutes = TimeUnit.MINUTES.convert(rawTz, TimeUnit.MILLISECONDS);
                String tzOffset = new DecimalFormat("#0.00").format(minutes / 60.0f);
                payload.put("timezone", tzOffset);

                String locale = Locale.getDefault().toString();
                payload.put("locale", locale);

                if (_this.deviceConfiguration.advertsingInfo != null) {
                    payload.put("android_ad_id", _this.deviceConfiguration.advertsingInfo.getId());
                    payload.put("android_limit_ad_tracking",
                            _this.deviceConfiguration.advertsingInfo.isLimitAdTrackingEnabled());
                }

                if (_this.facebookAccessToken != null) {
                    payload.put("access_token", _this.facebookAccessToken);
                }

                if (_this.launchedFromTeakNotifId != null) {
                    payload.put("teak_notif_id", Long.valueOf(_this.launchedFromTeakNotifId));
                }

                if (_this.launchedFromDeepLink != null) {
                    payload.put("deep_link", _this.launchedFromDeepLink);
                }

                if (_this.deviceConfiguration.gcmId != null) {
                    payload.put("gcm_push_key", _this.deviceConfiguration.gcmId);
                } else {
                    payload.put("gcm_push_key", "");
                }

                Log.d(LOG_TAG, "Identifying user: " + _this.userId);
                Log.d(LOG_TAG, "        Timezone: " + tzOffset);
                Log.d(LOG_TAG, "          Locale: " + locale);

                new Request("/games/" + _this.appConfiguration.appId + "/users.json", payload, _this) {
                    @Override
                    protected void done(int responseCode, String responseBody) {
                        try {
                            JSONObject response = new JSONObject(responseBody);

                            // TODO: Grab 'id' and 'game_id' from response and store for Parsnip

                            // Enable verbose logging if flagged
                            boolean enableVerboseLogging = response.optBoolean("verbose_logging");
                            if (Teak.debugConfiguration != null) {
                                Teak.debugConfiguration.setPreferenceForceDebug(enableVerboseLogging);
                            }

                            // Server requesting new push key.
                            if (response.optBoolean("reset_push_key", false)) {
                                _this.deviceConfiguration.reRegisterPushToken(_this.appConfiguration);
                            }

                            if (response.has("country_code")) {
                                _this.countryCode = response.getString("country_code");
                            }

                            // Prevent warning for 'do_not_track_event'
                            if (_this.state != State.UserIdentified) {
                                _this.setState(State.UserIdentified);
                            }
                        } catch (Exception ignored) {
                        }

                        super.done(responseCode, responseBody);
                    }
                }.run();
            }
        }
    }).start();
}

From source file:com.jelly.music.player.GMusicHelpers.MobileClientPlaylistEntriesSchema.java

@Override
public MobileClientPlaylistEntriesSchema fromJsonObject(JSONObject jsonObject) {
    if (jsonObject != null) {
        mKind = jsonObject.optString("kind", null);
        mPlaylistId = jsonObject.optString("playlistId", null);
        mCreationTimestamp = jsonObject.optString("creationTimestamp");
        mLastModifiedTimestamp = jsonObject.optString("lastModifiedTimestamp", null);
        mDeleted = jsonObject.optBoolean("deleted");
        mClientId = jsonObject.optString("clientId");
        mTrackId = jsonObject.optString("trackId");
        mId = jsonObject.optString("id");
        mSource = jsonObject.optString("source");
    }/*from  w  w w. j  a  va  2  s. co m*/

    //This method returns itself to support chaining.
    return this;
}

From source file:com.rapid.actions.Webservice.java

public Webservice(RapidHttpServlet rapidServlet, JSONObject jsonAction) throws Exception {
    // set the xml version
    super();// w  ww  . j av a2s .  co m

    // save all key/values from the json into the properties 
    for (String key : JSONObject.getNames(jsonAction)) {
        // add all json properties to our properties, except for query
        if (!"request".equals(key) && !"root".equals(key) && !"showLoading".equals(key)
                && !"successActions".equals(key) && !"errorActions".equals(key))
            addProperty(key, jsonAction.get(key).toString());
    }

    // try and build the query object
    JSONObject jsonQuery = jsonAction.optJSONObject("request");

    // check we got one
    if (jsonQuery != null) {
        // get the parameters                  
        ArrayList<Parameter> inputs = getParameters(jsonQuery.optJSONArray("inputs"));
        String type = jsonQuery.optString("type");
        String url = jsonQuery.optString("url");
        String action = jsonQuery.optString("action");
        String body = jsonQuery.optString("body");
        String transform = jsonQuery.optString("transform");
        String root = jsonQuery.optString("root");
        ArrayList<Parameter> outputs = getParameters(jsonQuery.optJSONArray("outputs"));
        // make the object
        _request = new Request(inputs, type, url, action, body, transform, root, outputs);
    }

    // look for showLoading
    _showLoading = jsonAction.optBoolean("showLoading");

    // grab any successActions
    JSONArray jsonSuccessActions = jsonAction.optJSONArray("successActions");
    // if we had some
    if (jsonSuccessActions != null) {
        // instantiate our success actions collection
        _successActions = Control.getActions(rapidServlet, jsonSuccessActions);
    }

    // grab any errorActions
    JSONArray jsonErrorActions = jsonAction.optJSONArray("errorActions");
    // if we had some
    if (jsonErrorActions != null) {
        // instantiate our error actions collection
        _errorActions = Control.getActions(rapidServlet, jsonErrorActions);
    }

}

From source file:net.geco.model.iojson.PersistentStore.java

public void importRunnersData(JSONStore store, Registry registry, Factory factory) throws JSONException {
    final int I_RUNNER = 0;
    final int I_ECARD = 1;
    final int I_RESULT = 2;
    JSONArray runnersData = store.getJSONArray(K.RUNNERS_DATA);
    for (int i = 0; i < runnersData.length(); i++) {
        JSONArray runnerTuple = runnersData.getJSONArray(i);

        JSONObject c = runnerTuple.getJSONObject(I_RUNNER);
        Runner runner = factory.createRunner();
        runner.setStartId(c.getInt(K.START_ID));
        runner.setFirstname(c.getString(K.FIRST));
        runner.setLastname(c.getString(K.LAST));
        runner.setEcard(c.getString(K.ECARD));
        runner.setClub(store.retrieve(c.getInt(K.CLUB), Club.class));
        runner.setCategory(store.retrieve(c.getInt(K.CAT), Category.class));
        runner.setCourse(store.retrieve(c.getInt(K.COURSE), Course.class));
        runner.setRegisteredStarttime(new Date(c.getLong(K.START)));
        runner.setArchiveId((Integer) c.opt(K.ARK));
        runner.setRentedEcard(c.optBoolean(K.RENT));
        runner.setNC(c.optBoolean(K.NC));
        registry.addRunner(runner);/*  w ww . j  a  v a2 s.  c o  m*/

        JSONObject d = runnerTuple.getJSONObject(I_ECARD);
        RunnerRaceData raceData = factory.createRunnerRaceData();
        raceData.setStarttime(new Date(d.getLong(K.START)));
        raceData.setFinishtime(new Date(d.getLong(K.FINISH)));
        raceData.setControltime(new Date(d.getLong(K.CHECK)));
        raceData.setReadtime(new Date(d.getLong(K.READ)));
        JSONArray p = d.getJSONArray(K.PUNCHES);
        Punch[] punches = new Punch[p.length() / 2];
        for (int j = 0; j < punches.length; j++) {
            punches[j] = factory.createPunch();
            punches[j].setCode(p.getInt(2 * j));
            punches[j].setTime(new Date(p.getLong(2 * j + 1)));
        }
        raceData.setPunches(punches);
        raceData.setRunner(runner);
        registry.addRunnerData(raceData);

        JSONObject r = runnerTuple.getJSONObject(I_RESULT);
        TraceData traceData = factory.createTraceData();
        traceData.setNbMPs(r.getInt(K.MPS));
        traceData.setNbExtraneous(r.optInt(K.EXTRA)); // MIGR v2.x -> v2.3
        JSONArray t = r.getJSONArray(K.TRACE);
        Trace[] trace = new Trace[t.length() / 2];
        for (int j = 0; j < trace.length; j++) {
            trace[j] = factory.createTrace(t.getString(2 * j), new Date(t.getLong(2 * j + 1)));
        }
        if (r.has(K.SECTION_DATA)) {
            SectionTraceData sectionData = (SectionTraceData) traceData;
            JSONArray sections = r.getJSONArray(K.SECTION_DATA);
            for (int j = 0; j < sections.length(); j++) {
                JSONArray section = sections.getJSONArray(j);
                sectionData.putSectionAt(store.retrieve(section.getInt(0), Section.class), section.getInt(1));
            }
        }
        JSONArray neut = r.getJSONArray(K.NEUTRALIZED);
        for (int j = 0; j < neut.length(); j++) {
            trace[neut.getInt(j)].setNeutralized(true);
        }
        traceData.setTrace(trace);
        raceData.setTraceData(traceData);

        RunnerResult result = factory.createRunnerResult();
        result.setRaceTime(r.optLong(K.RACE_TIME, TimeManager.NO_TIME_l)); // MIGR v2.x -> v2.2
        result.setResultTime(r.getLong(K.TIME));
        result.setStatus(Status.valueOf(r.getString(K.STATUS)));
        result.setTimePenalty(r.getLong(K.PENALTY));
        result.setManualTimePenalty(r.optLong(K.MANUAL_PENALTY, 0)); // MIGR v2.x -> v2.3
        raceData.setResult(result);
    }
}

From source file:com.example.protocol.STATUSES.java

public void fromJson(JSONObject jsonObject) throws JSONException {
    if (null == jsonObject) {
        return;//from ww  w.j a  va 2  s . c  om
    }

    JSONArray subItemArray;

    this.comments_count = jsonObject.optInt("comments_count");

    this.text = jsonObject.optString("text");

    this.in_reply_to_screen_name = jsonObject.optString("in_reply_to_screen_name");

    this.truncated = jsonObject.optBoolean("truncated");

    this.bmiddle_pic = jsonObject.optString("bmiddle_pic");

    this.thumbnail_pic = jsonObject.optString("thumbnail_pic");

    this.source = jsonObject.optString("source");

    this.favorited = jsonObject.optBoolean("favorited");

    this.original_pic = jsonObject.optString("original_pic");

    this.in_reply_to_status_id = jsonObject.optString("in_reply_to_status_id");

    this.reposts_count = jsonObject.optInt("reposts_count");

    this.created_at = jsonObject.optString("created_at");

    this.in_reply_to_user_id = jsonObject.optString("in_reply_to_user_id");

    subItemArray = jsonObject.optJSONArray("annotations");
    if (null != subItemArray) {
        for (int i = 0; i < subItemArray.length(); i++) {
            String subItemObject = subItemArray.optString(i);
            String subItem = subItemObject;
            this.annotations.add(subItem);
        }
    }

    this.mid = jsonObject.optString("mid");
    USER user = new USER();
    user.fromJson(jsonObject.optJSONObject("user"));
    this.user = user;
    return;
}