Example usage for org.json JSONObject optLong

List of usage examples for org.json JSONObject optLong

Introduction

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

Prototype

public long optLong(String key) 

Source Link

Document

Get an optional long value associated with a key, or zero if there is no such key or if the value is not a number.

Usage

From source file:com.vk.sdkweb.api.model.VKApiCommunityFull.java

public VKApiCommunityFull parse(JSONObject jo) {
    super.parse(jo);

    JSONObject city = jo.optJSONObject(CITY);
    if (city != null) {
        this.city = new VKApiCity().parse(city);
    }//from   w  ww . j av a  2  s  .  c o m
    JSONObject country = jo.optJSONObject(COUNTRY);
    if (country != null) {
        this.country = new VKApiCountry().parse(country);
    }

    JSONObject place = jo.optJSONObject(PLACE);
    if (place != null)
        this.place = new VKApiPlace().parse(place);

    description = jo.optString(DESCRIPTION);
    wiki_page = jo.optString(WIKI_PAGE);
    members_count = jo.optInt(MEMBERS_COUNT);

    JSONObject counters = jo.optJSONObject(COUNTERS);
    if (counters != null)
        this.counters = new Counters(place);

    start_date = jo.optLong(START_DATE);
    end_date = jo.optLong(END_DATE);
    can_post = ParseUtils.parseBoolean(jo, CAN_POST);
    can_see_all_posts = ParseUtils.parseBoolean(jo, CAN_SEE_ALL_POSTS);
    status = jo.optString(STATUS);

    JSONObject status_audio = jo.optJSONObject("status_audio");
    if (status_audio != null)
        this.status_audio = new VKApiAudio().parse(status_audio);

    contacts = new VKList<Contact>(jo.optJSONArray(CONTACTS), Contact.class);
    links = new VKList<Link>(jo.optJSONArray(LINKS), Link.class);
    fixed_post = jo.optInt(FIXED_POST);
    verified = ParseUtils.parseBoolean(jo, VERIFIED);
    blacklisted = ParseUtils.parseBoolean(jo, VERIFIED);
    site = jo.optString(SITE);
    return this;
}

From source file:com.vk.sdkweb.api.model.VKApiDocument.java

/**
 * Fills a Doc instance from JSONObject.
 *///from  w ww. ja  v a2s . co  m
public VKApiDocument parse(JSONObject jo) {
    id = jo.optInt("id");
    owner_id = jo.optInt("owner_id");
    title = jo.optString("title");
    size = jo.optLong("size");
    ext = jo.optString("ext");
    url = jo.optString("url");
    access_key = jo.optString("access_key");

    photo_100 = jo.optString("photo_100");
    if (!TextUtils.isEmpty(photo_100)) {
        photo.add(VKApiPhotoSize.create(photo_100, 100, 75));
    }
    photo_130 = jo.optString("photo_130");
    if (!TextUtils.isEmpty(photo_130)) {
        photo.add(VKApiPhotoSize.create(photo_130, 130, 100));
    }
    photo.sort();
    return this;
}

From source file:com.QuarkLabs.BTCeClient.services.CheckTickersService.java

@Override
protected void onHandleIntent(Intent intent) {

    SharedPreferences sh = PreferenceManager.getDefaultSharedPreferences(this);
    Set<String> x = sh.getStringSet("PairsToDisplay", new HashSet<String>());
    if (x.size() == 0) {
        return;/*from w w  w  .j  a  v  a 2  s  .co m*/
    }
    String[] pairs = x.toArray(new String[x.size()]);
    ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    String url = BASE_URL;
    for (String xx : pairs) {
        url += xx.replace("/", "_").toLowerCase(Locale.US) + "-";
    }
    SimpleRequest reqSim = new SimpleRequest();

    if (networkInfo != null && networkInfo.isConnected()) {
        JSONObject data = null;
        try {
            data = reqSim.makeRequest(url);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (data != null && data.optInt("success", 1) != 0) {

            ArrayList<Ticker> tickers = new ArrayList<>();
            for (@SuppressWarnings("unchecked")
            Iterator<String> iterator = data.keys(); iterator.hasNext();) {
                String key = iterator.next();
                JSONObject pairData = data.optJSONObject(key);
                Ticker ticker = new Ticker(key);
                ticker.setUpdated(pairData.optLong("updated"));
                ticker.setAvg(pairData.optDouble("avg"));
                ticker.setBuy(pairData.optDouble("buy"));
                ticker.setSell(pairData.optDouble("sell"));
                ticker.setHigh(pairData.optDouble("high"));
                ticker.setLast(pairData.optDouble("last"));
                ticker.setLow(pairData.optDouble("low"));
                ticker.setVol(pairData.optDouble("vol"));
                ticker.setVolCur(pairData.optDouble("vol_cur"));
                tickers.add(ticker);
            }

            String message = checkNotifiers(tickers, TickersStorage.loadLatestData());

            if (message.length() != 0) {
                NotificationManager notificationManager = (NotificationManager) getSystemService(
                        NOTIFICATION_SERVICE);
                NotificationCompat.Builder nb = new NotificationCompat.Builder(this)
                        .setContentTitle(getResources().getString(R.string.app_name))
                        .setSmallIcon(R.drawable.ic_stat_bitcoin_sign)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .setContentText(message.substring(0, message.length() - 2));
                notificationManager.notify(ConstantHolder.ALARM_NOTIF_ID, nb.build());
            }

            Map<String, Ticker> newData = new HashMap<>();
            for (Ticker ticker : tickers) {
                newData.put(ticker.getPair(), ticker);
            }
            TickersStorage.saveData(newData);
            LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("UpdateTickers"));
        }
    } else {
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                //Toast.makeText(CheckTickersService.this, "Unable to fetch data", Toast.LENGTH_SHORT).show();
            }
        });

    }
}

From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP0708xxDataImpl.java

public static EEP0708xxDataImpl constructDataFromRecord(JSONObject lastKnownData) {
    if (lastKnownData == null)
        return new EEP0708xxDataImpl(Float.MIN_VALUE, -1, Float.MIN_VALUE, PIRStatus.UNKNOWN, null, null);

    try {/*from  ww w .j av  a2 s  .  co m*/
        float supplyVoltage = (float) lastKnownData.getDouble("supplyVoltage");
        int illumination = lastKnownData.getInt("illumination");
        float temperature = (float) lastKnownData.getDouble("temperature");
        PIRStatus pirStatus = PIRStatus.valueOf(lastKnownData.getString("pirStatus"));
        long LOPBDate = lastKnownData.optLong("LOPBDate");
        Date date = new Date(lastKnownData.getLong("date"));

        return new EEP0708xxDataImpl(supplyVoltage, illumination, temperature, pirStatus,
                (LOPBDate == 0) ? null : new Date(LOPBDate), date);
    } catch (JSONException e) {
        Logger.error(LC.gi(), null,
                "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !",
                e);
        return new EEP0708xxDataImpl(Float.MIN_VALUE, -1, Float.MIN_VALUE, PIRStatus.UNKNOWN, null, null);
    }
}

From source file:com.basetechnology.s0.agentserver.field.IntField.java

public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) {
    String type = fieldJson.optString("type");
    if (type == null || !(type.equals("int") || type.equals("integer")))
        return null;
    String name = fieldJson.has("name") ? fieldJson.optString("name") : null;
    String label = fieldJson.has("label") ? fieldJson.optString("label") : null;
    String description = fieldJson.has("description") ? fieldJson.optString("description") : null;
    long defaultValue = fieldJson.has("default_value") ? fieldJson.optLong("default_value") : 0;
    long minValue = fieldJson.has("min_value") ? fieldJson.optLong("min_value") : Long.MIN_VALUE;
    long maxValue = fieldJson.has("max_value") ? fieldJson.optLong("max_value") : Long.MAX_VALUE;
    int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0;
    String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null;
    return new IntField(symbolTable, name, label, description, defaultValue, minValue, maxValue, nominalWidth,
            compute);//from   w ww .ja v a  2 s. co  m
}

From source file:de.luhmer.owncloudnewsreader.reader.owncloud.InsertFolderIntoDatabase.java

private static Folder parseFolder(JSONObject e) {
    return new Folder(e.optLong("id"), e.optString("name"));
}

From source file:org.sufficientlysecure.privacybox.VaultProvider.java

/**
 * Include metadata for a document in the given result cursor.
 *//*from  w  w w  . j  av a 2 s  . c  om*/
private void includeDocument(MatrixCursor result, long docId) throws IOException, GeneralSecurityException {
    final EncryptedDocument doc = getDocument(docId);
    if (!doc.getFile().exists()) {
        throw new FileNotFoundException("Missing document " + docId);
    }

    final JSONObject meta = doc.readMetadata();

    int flags = 0;

    final String mimeType = meta.optString(Document.COLUMN_MIME_TYPE);
    if (Document.MIME_TYPE_DIR.equals(mimeType)) {
        flags |= Document.FLAG_DIR_SUPPORTS_CREATE;
    } else {
        flags |= Document.FLAG_SUPPORTS_WRITE;
    }
    flags |= Document.FLAG_SUPPORTS_DELETE;

    final RowBuilder row = result.newRow();
    row.add(Document.COLUMN_DOCUMENT_ID, meta.optLong(Document.COLUMN_DOCUMENT_ID));
    row.add(Document.COLUMN_DISPLAY_NAME, meta.optString(Document.COLUMN_DISPLAY_NAME));
    row.add(Document.COLUMN_SIZE, meta.optLong(Document.COLUMN_SIZE));
    row.add(Document.COLUMN_MIME_TYPE, mimeType);
    row.add(Document.COLUMN_FLAGS, flags);
    row.add(Document.COLUMN_LAST_MODIFIED, meta.optLong(Document.COLUMN_LAST_MODIFIED));
}

From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP0710xxDataImpl.java

public static EEP0710xxDataImpl constructDataFromRecord(JSONObject lastKnownData) {
    if (lastKnownData == null)
        return new EEP0710xxDataImpl(Float.MIN_VALUE, Float.MIN_VALUE, FanSpeed.UNKNOWN, -1, null,
                DayNightState.UNKNOWN, null);

    try {//from  ww w.  j  a  va2s . c  om
        float temperature = (float) lastKnownData.getDouble("temperature");
        float relativeHumidity = (float) lastKnownData.getDouble("relativeHumidity");
        FanSpeed fanSpeed = FanSpeed.valueOf(lastKnownData.getString("fanSpeed"));
        int setPoint = lastKnownData.getInt("setPoint");
        long LOPBDate = lastKnownData.optLong("LOPBDate");
        DayNightState dayNightState = DayNightState.valueOf(lastKnownData.getString("dayNightState"));
        ;
        Date date = new Date(lastKnownData.getLong("date"));

        return new EEP0710xxDataImpl(temperature, relativeHumidity, fanSpeed, setPoint,
                (LOPBDate == 0) ? null : new Date(LOPBDate), dayNightState, date);
    } catch (JSONException e) {
        Logger.error(LC.gi(), null,
                "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !",
                e);
        return new EEP0710xxDataImpl(Float.MIN_VALUE, Float.MIN_VALUE, FanSpeed.UNKNOWN, -1, null,
                DayNightState.UNKNOWN, null);
    }
}

From source file:org.smilec.smile.bu.json.ResultsJSONParser.java

public static final Results process(JSONObject object) {

    int winnerScore = object.optInt(WINNER_SCORE);
    float winnerRating = object.optLong(WINNER_RATING);

    JSONArray optJSONArray = object.optJSONArray(BEST_SCORED_STUDENT_NAMES);
    JSONArray bestScoredStudentNames = optJSONArray == null ? new JSONArray() : optJSONArray;

    JSONArray optJSONArray2 = object.optJSONArray(BEST_RATED_QUESTION_STUDENT_NAMES);
    JSONArray bestRatedQuestionStudentNames = optJSONArray2 == null ? new JSONArray() : optJSONArray2;

    JSONArray optJSONArray3 = object.optJSONArray(RIGHT_ANSWERS);
    JSONArray rightAnswers = optJSONArray3 == null ? new JSONArray() : optJSONArray3;

    int numberOfQuestions = object.optInt(NUMBER_OF_QUESTIONS);

    JSONArray optJSONArray4 = object.optJSONArray(AVERAGE_RATINGS);
    JSONArray averageRatings = optJSONArray4 == null ? new JSONArray() : optJSONArray4;

    JSONArray optJSONArray5 = object.optJSONArray(QUESTIONS_CORRECT_PERCENTAGE);
    JSONArray questionsCorrectPercentage = optJSONArray5 == null ? new JSONArray() : optJSONArray5;

    Results results = new Results(winnerScore, winnerRating, bestScoredStudentNames,
            bestRatedQuestionStudentNames, numberOfQuestions, rightAnswers, averageRatings,
            questionsCorrectPercentage);

    return results;

}

From source file:com.vk.sdkweb.api.model.VKApiComment.java

/**
 * Fills a Comment instance from JSONObject.
 *//* w w  w  .  ja  v a 2 s.  com*/
public VKApiComment parse(JSONObject from) throws JSONException {
    id = from.optInt("id");
    from_id = from.optInt("from_id");
    date = from.optLong("date");
    text = from.optString("text");
    reply_to_user = from.optInt("reply_to_user");
    reply_to_comment = from.optInt("reply_to_comment");
    attachments.fill(from.optJSONArray("attachments"));
    JSONObject likes = from.optJSONObject("likes");
    this.likes = ParseUtils.parseInt(likes, "count");
    this.user_likes = ParseUtils.parseBoolean(likes, "user_likes");
    this.can_like = ParseUtils.parseBoolean(likes, "can_like");
    return this;
}