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:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java

/**
 *
 * @param wp/*from  w  w w  .java2  s .  c o  m*/
 * @return
 */
public boolean add(Waypoint wp) {
    boolean result = false;

    try {
        JSONObject wpJson = wp.toJson();
        String jsonStr = this.packageWaypointCall("add", wpJson);
        debug("sending: " + jsonStr);
        String resString = server.call(jsonStr);
        debug("got back: " + resString);
        JSONObject res = new JSONObject(resString);
        result = res.optBoolean("result");
    } catch (Exception ex) {
        System.out.println("exception in rpc call to add: " + ex.getMessage());
    }

    return result;
}

From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java

/**
 *
 * @param wpName/*  www.  ja v  a2  s  .  co  m*/
 * @return
 */
public boolean remove(String wpName) {
    boolean result = false;

    try {
        String jsonStr = this.packageWaypointCall("remove", wpName, null);
        debug("sending: " + jsonStr);
        String resString = server.call(jsonStr);
        debug("got back: " + resString);
        JSONObject res = new JSONObject(resString);
        result = res.optBoolean("result");
    } catch (Exception ex) {
        System.out.println("exception in rpc call to remove: " + ex.getMessage());
    }

    return result;
}

From source file:sh.calaba.driver.client.model.impl.RemoteObject.java

public JSONObject executeCalabashCommand(CalabashCommands calabashCommand, String... parameter) {
    try {/*w  w w  . j  a  va 2  s.  c o m*/
        JSONObject payload = new JSONObject();
        payload.put("command", calabashCommand.getCommand());
        payload.put("arguments", parameter);

        Object res = get(calabashCommand.getWebDriverLikeCommand(), payload);
        JSONObject result = ((JSONObject) res);

        if (result == null || !result.optBoolean("success")) {
            throw new CalabashException(
                    "Calabash command '" + calabashCommand.getCommand() + "' was not successful: " + result);
        }

        return result;
    } catch (JSONException e) {
        e.printStackTrace();
        throw new CalabashException("Error ocured while parsing calabash-driver response.", e);
    }
}

From source file:com.connectsdk.cordova.JSCommandDispatcher.java

void displayMedia(JSCommand command, JSONObject args, String type) throws JSONException {
    String url = args.getString("url");
    String mimeType = args.getString("mimeType");
    String title = args.optString("title");
    String description = args.optString("description");
    String iconSrc = args.optString("iconUrl");
    boolean shouldLoop = args.optBoolean("shouldLoop");

    if ("image".equals(type)) {
        device.getMediaPlayer().displayImage(url, mimeType, title, description, iconSrc,
                command.getMediaLaunchListener());
    } else {//from  www. j av  a 2  s.  c om
        device.getMediaPlayer().playMedia(url, mimeType, title, description, iconSrc, shouldLoop,
                command.getMediaLaunchListener());
    }
}

From source file:com.facebook.share.internal.LikeActionController.java

private static LikeActionController deserializeFromJson(String controllerJsonString) {
    LikeActionController controller;//from   ww w .j av  a  2 s .  c  om

    try {
        JSONObject controllerJson = new JSONObject(controllerJsonString);
        int version = controllerJson.optInt(JSON_INT_VERSION_KEY, -1);
        if (version != LIKE_ACTION_CONTROLLER_VERSION) {
            // Don't attempt to deserialize a controller that might be serialized differently
            // than expected.
            return null;
        }

        String objectId = controllerJson.getString(JSON_STRING_OBJECT_ID_KEY);
        int objectTypeInt = controllerJson.optInt(JSON_INT_OBJECT_TYPE_KEY,
                LikeView.ObjectType.UNKNOWN.getValue());

        controller = new LikeActionController(objectId, LikeView.ObjectType.fromInt(objectTypeInt));

        // Make sure to default to null and not empty string, to keep the logic elsewhere
        // functioning properly.
        controller.likeCountStringWithLike = controllerJson.optString(JSON_STRING_LIKE_COUNT_WITH_LIKE_KEY,
                null);
        controller.likeCountStringWithoutLike = controllerJson
                .optString(JSON_STRING_LIKE_COUNT_WITHOUT_LIKE_KEY, null);
        controller.socialSentenceWithLike = controllerJson.optString(JSON_STRING_SOCIAL_SENTENCE_WITH_LIKE_KEY,
                null);
        controller.socialSentenceWithoutLike = controllerJson
                .optString(JSON_STRING_SOCIAL_SENTENCE_WITHOUT_LIKE_KEY, null);
        controller.isObjectLiked = controllerJson.optBoolean(JSON_BOOL_IS_OBJECT_LIKED_KEY);
        controller.unlikeToken = controllerJson.optString(JSON_STRING_UNLIKE_TOKEN_KEY, null);

        JSONObject analyticsJSON = controllerJson.optJSONObject(JSON_BUNDLE_FACEBOOK_DIALOG_ANALYTICS_BUNDLE);
        if (analyticsJSON != null) {
            controller.facebookDialogAnalyticsBundle = BundleJSONConverter.convertToBundle(analyticsJSON);
        }
    } catch (JSONException e) {
        Log.e(TAG, "Unable to deserialize controller from JSON", e);
        controller = null;
    }

    return controller;
}

From source file:fr.haploid.webservices.WebServicesTask.java

public WebServicesTask(CobaltFragment fragment, JSONObject call) {
    mFragment = fragment;//from  ww  w . j a v a  2  s . c o  m
    mCall = call;

    try {
        mCallId = call.getLong(kJSCallId);
        JSONObject data = call.getJSONObject(Cobalt.kJSData);
        mSendCacheResult = data.optBoolean(kJSSendCacheResult);
        mUrl = data.optString(kJSUrl, null);

        if (mUrl != null) {
            mHeaders = data.optJSONObject(kJSHeaders);
            mParams = data.optString(kJSParams);
            mTimeout = data.optInt(kJSTimeout, -1);
            mType = data.getString(kJSType);
            mSaveToStorage = data.optBoolean(kJSSaveToStorage);
        }

        if (mSendCacheResult || mUrl != null)
            mProcessData = data.optJSONObject(kJSProcessData);

        if (mSendCacheResult || (mUrl != null && mSaveToStorage)) {
            mStorageKey = data.getString(kJSStorageKey);
        }
    } catch (JSONException exception) {
        if (Cobalt.DEBUG) {
            Log.e(WebServicesPlugin.TAG, TAG + ": check your Webservice call. Known issues: \n"
                    + "\t- missing data field, \n" + "\t- url field is defined but but missing type field, \n"
                    + "\t- sendCacheResult field is true or url field is defined and saveToStorage field is true but missing storageKey field.\n");
            exception.printStackTrace();
        }
    }
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PaxosPacket.java

/**
 * @param json//from   w  w  w  .  j av a 2 s  . c  om
 * @return True if packet generated during recovery mode.
 * @throws JSONException
 */
public static boolean isRecovery(JSONObject json) throws JSONException {
    return json.optBoolean(PaxosPacket.Keys.RCVRY.toString());
}

From source file:edu.umass.cs.gigapaxos.paxospackets.PValuePacket.java

public PValuePacket(JSONObject json) throws JSONException {
    super(json);/*  w  ww  . j  av a2s  .co m*/
    this.ballot = new Ballot(json.getString(PaxosPacket.NodeIDKeys.B.toString()));
    this.medianCheckpointedSlot = json.getInt(PaxosPacket.Keys.GC_S.toString());
    this.recovery = json.optBoolean(PaxosPacket.Keys.RCVRY.toString());
    this.packetType = PaxosPacket.getPaxosPacketType(json);
    this.noCoalesce = json.optBoolean(PaxosPacket.Keys.NO_COALESCE.toString());
}

From source file:edu.umass.cs.gigapaxos.paxospackets.RequestPacket.java

public RequestPacket(JSONObject json) throws JSONException {
    super(json);//from   w  ww  .  j av a2  s .co  m
    this.packetType = PaxosPacketType.REQUEST;
    this.stop = json.optBoolean(Keys.STOP.toString());
    this.requestID = json.getLong(Keys.QID.toString());
    this.requestValue = json.getString(Keys.QV.toString());

    this.responseValue = json.has(Keys.RV.toString()) ? json.getString(Keys.RV.toString()) : null;
    this.entryTime = json.getLong(Keys.ET.toString());
    this.forwardCount = (json.has(Keys.NFWDS.toString()) ? json.getInt(Keys.NFWDS.toString()) : 0);
    this.forwarderID = (json.has(RequestPacket.Keys.FWDR.toString())
            ? json.getInt(RequestPacket.Keys.FWDR.toString())
            : IntegerMap.NULL_INT_NODE);
    this.debugInfo = (json.has(Keys.DBG.toString()) ? json.getString(Keys.DBG.toString()) : "");

    this.clientAddress = (json.has(Keys.CA.toString())
            ? Util.getInetSocketAddressFromString(json.getString(Keys.CA.toString()))
            : JSONNIOTransport.getSenderAddress(json));
    this.listenAddress = (json.has(Keys.LA.toString())
            ? Util.getInetSocketAddressFromString(json.getString(Keys.LA.toString()))
            : JSONNIOTransport.getReceiverAddress(json));

    this.entryReplica = json.getInt(PaxosPacket.NodeIDKeys.E.toString());
    this.shouldReturnRequestValue = json.optBoolean(Keys.QF.toString());

    // unwrap latched along batch
    JSONArray batchedJSON = json.has(Keys.BATCH.toString()) ? json.getJSONArray(Keys.BATCH.toString()) : null;
    if (batchedJSON != null && batchedJSON.length() > 0) {
        this.batched = new RequestPacket[batchedJSON.length()];
        for (int i = 0; i < batchedJSON.length(); i++) {
            this.batched[i] = new RequestPacket((JSONObject) batchedJSON.get(i)
            // new JSONObject(batchedJSON.getString(i))
            );
        }
    }

    // we remembered the original string for recalling here
    this.stringifiedSelf = json.has(Keys.STRINGIFIED.toString())
            ? (String) json.get(Keys.STRINGIFIED.toString())
            : null;

    if (json.has(Keys.BC.toString()))
        this.broadcasted = json.getBoolean(Keys.BC.toString());
    if (json.has(Keys.DIG.toString()))
        try {
            this.digest = json.getString(Keys.DIG.toString()).getBytes(CHARSET);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
}

From source file:com.liferay.alerts.model.PollsChoice.java

public PollsChoice(JSONObject choice) throws JSONException {
    _choiceId = choice.getInt(CHOICE_ID);
    _description = choice.getString(DESCRIPTION);
    _checked = choice.optBoolean(CHECKED);
}