Example usage for org.json JSONObject getBoolean

List of usage examples for org.json JSONObject getBoolean

Introduction

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

Prototype

public boolean getBoolean(String key) throws JSONException 

Source Link

Document

Get the boolean value associated with a key.

Usage

From source file:com.hotstar.player.adplayer.feeds.ReferencePlayerFeedItemAdapter.java

/**
 * Creates and returns a metadata object for custom ad markers
 * /*from   w  ww  .  j  a v  a  2s .  c  o  m*/
 * @param jsonObject
 *            - to be parsed
 * @return AdvertisingMetadata - containing a TimeRangeCollection of
 *         TimeRanges for each custom ad marker, also sets the
 *         adjust-seek-position option
 * @throws JSONException
 *             if there is an error parsing the JSON object
 */
protected AdvertisingMetadata createCustomAdMarkers(JSONObject jsonObject) throws JSONException {
    AdvertisingMetadata result = new AdvertisingMetadata();

    TimeRangeCollection timeRangeCollection = new TimeRangeCollection(TimeRangeCollection.Type.MARK_RANGES);
    boolean isAdjustSeekPositionEnabled = jsonObject
            .getBoolean(NODE_NAME_CUSTOM_AD_MARKERS_ADJUST_SEEK_POSITION);
    JSONArray jsonArray = jsonObject.getJSONArray(NODE_NAME_CUSTOM_AD_MARKERS_TIME_RANGES);

    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject aJsonObject = jsonArray.getJSONObject(i);
        Long begin = Long.parseLong(aJsonObject.getString(NODE_NAME_CUSTOM_AD_MARKER_BEGIN));
        Long end = Long.parseLong(aJsonObject.getString(NODE_NAME_CUSTOM_AD_MARKER_END));

        TimeRange timeRange = TimeRange.createRange(begin, end - begin);
        timeRangeCollection.addTimeRange(timeRange);
    }

    Metadata options = new MetadataNode();
    if (isAdjustSeekPositionEnabled) {
        options.setValue(DefaultMetadataKeys.METADATA_KEY_ADJUST_SEEK_ENABLED.getValue(), VALUE_TRUE);
    } else {
        options.setValue(DefaultMetadataKeys.METADATA_KEY_ADJUST_SEEK_ENABLED.getValue(), VALUE_FALSE);
    }

    result.setNode(DefaultMetadataKeys.CUSTOM_AD_MARKERS_METADATA_KEY.getValue(),
            (MetadataNode) timeRangeCollection.toMetadata(options));
    return result;
}

From source file:de.btobastian.javacord.entities.permissions.impl.ImplRole.java

/**
 * Creates a new instance of this class.
 *
 * @param data A JSONObject containing all necessary data.
 * @param server The server of the role.
 * @param api The api of this server.//from  w  w w.  j  av a  2 s  . c o m
 */
public ImplRole(JSONObject data, ImplServer server, ImplDiscordAPI api) {
    this.server = server;
    this.api = api;

    id = data.getString("id");
    name = data.getString("name");
    permissions = new ImplPermissions(data.getInt("permissions"));
    position = data.getInt("position");
    color = new Color(data.getInt("color"));
    hoist = data.getBoolean("hoist");
    mentionable = data.getBoolean("mentionable");
    managed = data.getBoolean("managed");

    server.addRole(this);
}

From source file:cn.code.notes.gtask.data.Task.java

public void setContentByRemoteJSON(JSONObject js) {
    if (js != null) {
        try {//from  w ww. ja  va 2  s  .  c  om
            // id
            if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
                setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
            }

            // last_modified
            if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
                setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
            }

            // name
            if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
                setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
            }

            // notes
            if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
                setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
            }

            // deleted
            if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
                setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
            }

            // completed
            if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
                setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
            }
        } catch (JSONException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
            throw new ActionFailureException("fail to get task content from jsonobject");
        }
    }
}

From source file:org.onebusaway.gtfs_transformer.factory.TransformFactory.java

private void handleRetainOperation(String line, JSONObject json)
        throws JSONException, TransformSpecificationException {

    RetainEntitiesTransformStrategy strategy = getStrategy(RetainEntitiesTransformStrategy.class);

    TypedEntityMatch match = getMatch(line, json);

    boolean retainUp = true;

    if (json.has("retainUp"))
        retainUp = json.getBoolean("retainUp");

    strategy.addRetention(match, retainUp);

    if (json.has("retainBlocks")) {
        boolean retainBlocks = json.getBoolean("retainBlocks");
        strategy.setRetainBlocks(retainBlocks);
    }/*from ww w .  ja va 2s.  c om*/
}

From source file:jessmchung.groupon.parsers.DealParser.java

@Override
public Deal parse(JSONObject json) throws JSONException {
    Deal obj = new Deal();
    if (json.has("type"))
        obj.setType(json.getString("type"));
    if (json.has("shippingAddressRequired"))
        obj.setShippingAddressRequired(json.getBoolean("shippingAddressRequired"));
    if (json.has("isTipped"))
        obj.setIsTipped(json.getBoolean("isTipped"));
    if (json.has("textAd")) {
        JSONObject textAd = json.getJSONObject("textAd");
        obj.setTextAd(new TextAdParser().parse(textAd));
    }//  w  w  w.j  a v a 2s  .co  m
    if (json.has("merchant")) {
        JSONObject merchant = json.getJSONObject("merchant");
        obj.setMerchant(new MerchantParser().parse(merchant));
    }
    if (json.has("soldQuantity"))
        obj.setSoldQuantity(json.getInt("soldQuantity"));
    if (json.has("status"))
        obj.setStatus(json.getString("status"));
    if (json.has("largeImageUrl"))
        obj.setLargeImageUrl(json.getString("largeImageUrl"));
    if (json.has("dealUrl"))
        obj.setDealUrl(json.getString("dealUrl"));
    if (json.has("tippedAt")) {
        try {
            obj.setTippedAt(parseDate(json.getString("tippedAt")));
        } catch (ParseException ex) {
            System.out.println("Could not parse " + json.getString("tippedAt"));
        }
    }
    if (json.has("plcementPriority"))
        obj.setPlacementPriority(json.getString("placementPriority"));
    if (json.has("pitchHtml"))
        obj.setPitchHtml(json.getString("pitchHtml"));
    if (json.has("sidebarImageUrl"))
        obj.setSidebarImageUrl(json.getString("sidebarImageUrl"));
    if (json.has("startAt")) {
        try {
            obj.setStartAt(parseDate(json.getString("startAt")));
        } catch (ParseException ex) {
            System.out.println("Could not parse " + json.getString("startAt"));
        }
    }
    if (json.has("endAt")) {
        try {
            obj.setEndAt(parseDate(json.getString("endAt")));
        } catch (ParseException ex) {
            System.out.println("Could not parse " + json.getString("endAt"));
        }
    }
    if (json.has("mediumImageUrl"))
        obj.setMediumImageUrl(json.getString("mediumImageUrl"));
    if (json.has("highlightsHtml"))
        obj.setHighlightsHtml(json.getString("highlightsHtml"));
    if (json.has("title"))
        obj.setTitle(json.getString("title"));
    if (json.has("options")) {
        JSONArray dealOptions = json.getJSONArray("options");
        obj.setOptions(new DealOptionsParser().parse(dealOptions));
    }
    if (json.has("tippingPoint"))
        obj.setTippingPoint(json.getInt("tippingPoint"));
    if (json.has("id"))
        obj.setId(json.getString("id"));
    if (json.has("announcementTitle"))
        obj.setAnnouncementTitle(json.getString("announcementTitle"));
    if (json.has("isSoldOut"))
        obj.setIsSoldOut(json.getBoolean("isSoldOut"));
    if (json.has("division")) {
        JSONObject division = json.getJSONObject("division");
        obj.setDivision(new DivisionParser().parse(division));
    }
    if (json.has("emailImageUrl"))
        obj.setEmailImageUrl(json.getString("emailImageUrl"));

    return obj;
}

From source file:com.newtifry.android.database.NewtifrySource.java

public void fromJSONObject(JSONObject source) throws JSONException {
    this.changeTimestamp = source.getString("updated");
    this.title = source.getString("title");
    this.serverEnabled = source.getBoolean("enabled");
    this.sourceKey = source.getString("key");
    this.serverId = source.getLong("id");
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static <T> Object saveOrUpdateEntityFromJSON(Class<T> clazz, long id, JSONObject jsonObjectEntity) {
    if (!jsonObjectEntity.has("name")) {
        return null;
    }/*from w ww  .j  a v  a2  s  .co  m*/
    MyEntity tEntity = (MyEntity) em.get(clazz, id);
    if (tEntity == null) {
        if (clazz == Project.class) {
            tEntity = new Project();
        } else if (clazz == Payee.class) {
            tEntity = new Payee();
        }
        tEntity.id = KEY_CREATE;
    }
    //---
    try {
        tEntity.remoteKey = jsonObjectEntity.getString("key");
        ((MyEntity) tEntity).title = jsonObjectEntity.getString("name");
        if ((clazz) == Project.class) {
            if (jsonObjectEntity.has("is_active")) {
                if (jsonObjectEntity.getBoolean("is_active")) {
                    ((Project) tEntity).isActive = true;
                } else {
                    ((Project) tEntity).isActive = false;
                }
            }
        }
        em.saveOrUpdate((MyEntity) tEntity);
        return tEntity;
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateBudgetFromJSON(long id, JSONObject jsonObjectEntity) throws JSONException {
    Budget tEntity = em.get(Budget.class, id);
    if (tEntity == null) {
        tEntity = new Budget();
        tEntity.id = KEY_CREATE;//from w  w  w  . jav a  2  s.  co  m
    }
    try {
        tEntity.remoteKey = jsonObjectEntity.getString("key");
    } catch (JSONException e2) {
        e2.printStackTrace();
    }
    if (jsonObjectEntity.has("title")) {
        try {
            tEntity.title = jsonObjectEntity.getString("title");
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("categories")) {
        try {
            String[] strArrCategories = jsonObjectEntity.getString("categories").split(",");
            tEntity.categories = "";
            for (String key : strArrCategories) {
                tEntity.categories += getLocalKey(DatabaseHelper.CATEGORY_TABLE, key) + ",";
            }
            if (tEntity.categories.endsWith(",")) {
                tEntity.categories = tEntity.categories.substring(0, tEntity.categories.length() - 1);
            }
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Budget categories");
            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("projects")) {
        try {
            String[] strArrProjects = jsonObjectEntity.getString("projects").split(",");
            tEntity.projects = "";
            for (String key : strArrProjects) {
                tEntity.projects += getLocalKey(DatabaseHelper.PROJECT_TABLE, key) + ",";
            }
            if (tEntity.projects.endsWith(",")) {
                tEntity.projects = tEntity.projects.substring(0, tEntity.projects.length() - 1);
            }
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Budget.project_id ");
            e.printStackTrace();
        }
    }
    //      if (jsonObjectEntity.has("currency")) {
    //         try {
    //            tEntity.currencyId=getLocalKey(DatabaseHelper.CURRENCY_TABLE, jsonObjectEntity.getString("currency"));
    //         } catch (Exception e) {
    //            Log.e(TAG,"Error parsing Budget.currency ");
    //            e.printStackTrace();
    //         }
    //      }
    if (jsonObjectEntity.has("budget_account_id")) {
        try {
            tEntity.account = em.load(Account.class,
                    getLocalKey(DatabaseHelper.ACCOUNT_TABLE, jsonObjectEntity.getString("budget_account_id")));
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Budget.budget_account_id ");
            e.printStackTrace();
        }
    } else {
        if (jsonObjectEntity.has("budget_currency_id")) {
            try {
                tEntity.currency = em.load(Currency.class, getLocalKey(DatabaseHelper.CURRENCY_TABLE,
                        jsonObjectEntity.getString("budget_currency_id")));
                tEntity.currencyId = getLocalKey(DatabaseHelper.CURRENCY_TABLE,
                        jsonObjectEntity.getString("budget_currency_id"));
            } catch (Exception e) {
                Log.e(TAG, "Error parsing Budget.budget_currency_id ");
                e.printStackTrace();
            }
        }
    }
    if (jsonObjectEntity.has("amount2")) {
        try {
            tEntity.amount = jsonObjectEntity.getInt("amount2");
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Budget.amount");
            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("includeSubcategories")) {
        tEntity.includeSubcategories = jsonObjectEntity.getBoolean("includeSubcategories");
    }
    if (jsonObjectEntity.has("expanded")) {
        tEntity.expanded = jsonObjectEntity.getBoolean("expanded");
    }
    if (jsonObjectEntity.has("includeCredit")) {
        tEntity.includeCredit = jsonObjectEntity.getBoolean("includeCredit");
    }
    if (jsonObjectEntity.has("startDate")) {
        try {
            tEntity.startDate = jsonObjectEntity.getLong("startDate") * 1000;
        } catch (Exception e1) {
            Log.e(TAG, "Error parsing Budget.startDate");
            e1.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("endDate")) {
        try {
            tEntity.endDate = jsonObjectEntity.getLong("endDate") * 1000;
        } catch (Exception e1) {
            Log.e(TAG, "Error parsing Budget.endDate");
            e1.printStackTrace();
        }
    }

    if (jsonObjectEntity.has("recurNum")) {
        try {
            tEntity.recurNum = jsonObjectEntity.getInt("recurNum");
        } catch (JSONException e) {

            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("isCurrent")) {
        try {
            tEntity.isCurrent = jsonObjectEntity.getBoolean("isCurrent");
        } catch (JSONException e) {

            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("parentBudgetId")) {
        try {
            tEntity.parentBudgetId = getLocalKey(DatabaseHelper.BUDGET_TABLE,
                    jsonObjectEntity.getString("parentBudgetId"));
        } catch (Exception e) {
            Log.e(TAG, "Error parsing Budget.parentBudgetId ");
            e.printStackTrace();
        }
    }
    if (jsonObjectEntity.has("recur")) {
        try {
            tEntity.recur = jsonObjectEntity.getString("recur");
        } catch (JSONException e) {

            e.printStackTrace();
        }
    }
    em.saveOrUpdate(tEntity);
    return tEntity;
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateLocationFromJSON(long id, JSONObject jsonObjectEntity) {
    MyLocation tEntity = em.get(MyLocation.class, id);
    if (tEntity == null) {
        tEntity = new MyLocation();
        tEntity.id = KEY_CREATE;/*  w w  w . ja va  2  s  . c  om*/
    }
    try {
        tEntity.remoteKey = jsonObjectEntity.getString("key");
        if (jsonObjectEntity.has("name")) {
            tEntity.name = jsonObjectEntity.getString("name");
        } else {
            tEntity.name = "---";
        }
        if (jsonObjectEntity.has("provider")) {
            tEntity.provider = jsonObjectEntity.getString("provider");
        }
        if (jsonObjectEntity.has("accuracy")) {
            try {
                tEntity.accuracy = Float.valueOf(jsonObjectEntity.getString("accuracy"));
            } catch (Exception e) {
                Log.e(TAG,
                        "Error parsing MyLocation.accuracy with : " + jsonObjectEntity.getString("accuracy"));
            }
        }
        if (jsonObjectEntity.has("lon")) {
            tEntity.longitude = jsonObjectEntity.getDouble("lon");
        }
        if (jsonObjectEntity.has("lat")) {
            tEntity.latitude = jsonObjectEntity.getDouble("lat");
        }
        if (jsonObjectEntity.has("is_payee")) {
            if (jsonObjectEntity.getBoolean("is_payee")) {
                tEntity.isPayee = true;
            } else {
                tEntity.isPayee = false;
            }
        }
        if (jsonObjectEntity.has("resolved_adress")) {
            tEntity.resolvedAddress = jsonObjectEntity.getString("resolved_adress");
        }
        if (jsonObjectEntity.has("dateOfEmission")) {
            try {
                tEntity.dateTime = jsonObjectEntity.getLong("dateOfEmission");
            } catch (Exception e1) {
                Log.e(TAG, "Error parsing MyLocation.dateTime with : "
                        + jsonObjectEntity.getString("dateOfEmission"));
            }
        }
        if (jsonObjectEntity.has("count")) {
            tEntity.count = jsonObjectEntity.getInt("count");
        }
        if (jsonObjectEntity.has("dateTime")) {
            tEntity.dateTime = jsonObjectEntity.getLong("dateTime");
        }
        if (jsonObjectEntity.has("dateTime")) {
            tEntity.dateTime = jsonObjectEntity.getLong("dateTime");
        }
        em.saveOrUpdate(tEntity);
        return tEntity;
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncEngine.java

public static Object saveOrUpdateCurrencyFromJSON(long id, JSONObject jsonObjectEntity) {
    Currency tEntity = em.get(Currency.class, id);
    if (tEntity == null) {
        tEntity = Currency.EMPTY;
        tEntity.id = KEY_CREATE;/*from   w  w  w . j  ava 2  s .  c  om*/
    }
    try {
        tEntity.remoteKey = jsonObjectEntity.getString("key");
        if (jsonObjectEntity.has("title")) {
            tEntity.title = jsonObjectEntity.getString("title");
        }
        if (jsonObjectEntity.has("name")) {
            tEntity.name = jsonObjectEntity.getString("name");
        }
        //deduplicate if server already have the currency
        String sql = "select _id from " + DatabaseHelper.CURRENCY_TABLE + " where name= '" + tEntity.name
                + "';";
        Cursor c = db.rawQuery(sql, null);

        if (c.moveToFirst()) {
            tEntity.id = c.getLong(0);
            c.close();
        } else {
            c.close();
        }
        if (jsonObjectEntity.has("symbol")) {
            try {
                tEntity.symbol = jsonObjectEntity.getString("symbol");
            } catch (Exception e) {
                Log.e(TAG, "Error pulling Currency.symbol");
                e.printStackTrace();
            }
        }
        tEntity.isDefault = false;
        if (jsonObjectEntity.has("isDefault")) {
            if (jsonObjectEntity.getBoolean("isDefault")) {
                tEntity.isDefault = jsonObjectEntity.getBoolean("isDefault");
            }
        }
        if (jsonObjectEntity.has("decimals")) {
            try {
                tEntity.decimals = jsonObjectEntity.getInt("decimals");
            } catch (Exception e) {
                Log.e(TAG, "Error pulling Currency.decimals");
                e.printStackTrace();
            }
        }
        try {
            tEntity.decimalSeparator = jsonObjectEntity.getString("decimalSeparator");
        } catch (Exception e) {
            Log.e(TAG, "Error pulling Currency.symbol");
        }
        try {
            tEntity.groupSeparator = jsonObjectEntity.getString("groupSeparator");
        } catch (Exception e) {
            Log.e(TAG, "Error pulling Currency.symbol");
        }
        em.saveOrUpdate(tEntity);
        return tEntity;
    } catch (Exception e) {
        e.printStackTrace();
        return e;
    }
}