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:uk.co.pilllogger.billing.Purchase.java

public Purchase(String jsonPurchaseInfo, String signature) throws JSONException {
    mOriginalJson = jsonPurchaseInfo;/*from ww  w  . jav  a  2s.c o  m*/
    JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mPurchaseState = o.optInt("purchaseState");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mSignature = signature;
}

From source file:com.segma.trim.InAppBillingUtilities.StockKeepingUnitDetails.java

public StockKeepingUnitDetails(String itemType, String jsonSkuDetails) throws JSONException {
    mItemType = itemType;// w w  w .j a v  a 2 s .  c  om
    mJson = jsonSkuDetails;
    JSONObject o = new JSONObject(mJson);
    mSku = o.optString("productId");
    mType = o.optString("type");
    mPrice = o.optString("price");
    mPriceAmountMicros = o.optLong("price_amount_micros");
    mPriceCurrencyCode = o.optString("price_currency_code");
    mTitle = o.optString("title");
    mDescription = o.optString("description");
}

From source file:org.catnut.support.TransientUser.java

public static TransientUser convert(JSONObject jsonObject) {
    TransientUser user = new TransientUser();
    user.id = jsonObject.optLong(Constants.ID);
    user.screenName = jsonObject.optString(User.screen_name);
    user.location = jsonObject.optString(User.location);
    user.description = jsonObject.optString(User.description);
    user.verified = jsonObject.optBoolean(User.verified);
    user.avatarUrl = jsonObject.optString(User.profile_image_url);
    return user;/*from   w  w w.  j ava 2  s . c  om*/
}

From source file:com.bojie.weatherbo.ui.inappbilling.Purchase.java

public Purchase(final String itemType, final String jsonPurchaseInfo, final String signature)
        throws JSONException {
    mItemType = itemType;/*from   w ww.java2 s  .co  m*/
    mOriginalJson = jsonPurchaseInfo;
    final JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mPurchaseState = o.optInt("purchaseState");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mSignature = signature;
}

From source file:org.mariotaku.twidere.extension.mediauploader.util.ParseUtils.java

public static Bundle jsonToBundle(final String string) {
    final Bundle bundle = new Bundle();
    if (string != null) {
        try {/*w  w  w .  j  a v a  2 s  . c  o  m*/
            final JSONObject json = new JSONObject(string);
            final Iterator<?> it = json.keys();
            while (it.hasNext()) {
                final Object key_obj = it.next();
                if (key_obj == null) {
                    continue;
                }
                final String key = key_obj.toString();
                final Object value = json.get(key);
                if (value instanceof Boolean) {
                    bundle.putBoolean(key, json.optBoolean(key));
                } else if (value instanceof Integer) {
                    // Simple workaround for account_id
                    if (shouldPutLong(key)) {
                        bundle.putLong(key, json.optLong(key));
                    } else {
                        bundle.putInt(key, json.optInt(key));
                    }
                } else if (value instanceof Long) {
                    bundle.putLong(key, json.optLong(key));
                } else if (value instanceof String) {
                    bundle.putString(key, json.optString(key));
                } else {
                    Log.w(LOGTAG,
                            "Unknown type " + value.getClass().getSimpleName() + " in arguments key " + key);
                }
            }
        } catch (final JSONException e) {
            e.printStackTrace();
        } catch (final ClassCastException e) {
            e.printStackTrace();
        }
    }
    return bundle;
}

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

/**
 * Fills a Video instance from JSONObject.
 *//*w  w  w  .  j a v  a2s.  c  om*/
public VKApiVideo parse(JSONObject from) {
    id = from.optInt("id");
    owner_id = from.optInt("owner_id");
    title = from.optString("title");
    description = from.optString("description");
    duration = from.optInt("duration");
    link = from.optString("link");
    date = from.optLong("date");
    views = from.optInt("views");
    comments = from.optInt("comments");
    player = from.optString("player");
    access_key = from.optString("access_key");
    album_id = from.optInt("album_id");

    JSONObject likes = from.optJSONObject("likes");
    if (likes != null) {
        this.likes = likes.optInt("count");
        user_likes = parseBoolean(likes, "user_likes");
    }
    can_comment = parseBoolean(from, "can_comment");
    can_repost = parseBoolean(from, "can_repost");
    repeat = parseBoolean(from, "repeat");

    privacy_view = VKPrivacy.parsePrivacy(from.optJSONObject("privacy_view"));
    privacy_comment = VKPrivacy.parsePrivacy(from.optJSONObject("privacy_comment"));

    JSONObject files = from.optJSONObject("files");
    if (files != null) {
        mp4_240 = files.optString("mp4_240");
        mp4_360 = files.optString("mp4_360");
        mp4_480 = files.optString("mp4_480");
        mp4_720 = files.optString("mp4_720");
        external = files.optString("external");
    }

    photo_130 = from.optString("photo_130");
    if (!TextUtils.isEmpty(photo_130)) {
        photo.add(VKApiPhotoSize.create(photo_130, 130));
    }

    photo_320 = from.optString("photo_320");
    if (!TextUtils.isEmpty(photo_320)) {
        photo.add(VKApiPhotoSize.create(photo_320, 320));
    }

    photo_640 = from.optString("photo_640");
    if (!TextUtils.isEmpty(photo_640)) {
        photo.add(VKApiPhotoSize.create(photo_640, 640));
    }
    return this;
}

From source file:com.fuse.billing.android.SkuDetails.java

public SkuDetails(JSONObject o) {
    mJson = o;//  w  w  w. j  a  v a 2s  .  c  o  m
    mSku = o.optString("productId");
    mType = o.optString("type");
    mPrice = o.optString("price");
    mPriceAmountMicros = o.optLong("price_amount_micros");
    mPriceCurrencyCode = o.optString("price_currency_code");
    mTitle = o.optString("title");
    mDescription = o.optString("description");
}

From source file:org.catnut.metadata.Status.java

@Override
public ContentValues convert(JSONObject json) {
    ContentValues tweet = new ContentValues();
    tweet.put(BaseColumns._ID, json.optLong(Constants.ID));
    tweet.put(created_at, json.optString(created_at));
    // ?jsonsql???
    tweet.put(columnText, json.optString(text));
    tweet.put(source, json.optString(source));
    tweet.put(favorited, json.optBoolean(favorited));
    tweet.put(truncated, json.optBoolean(truncated));
    // ??????// w  ww .j  ava 2 s .  c  om
    JSONArray thumbs = json.optJSONArray(pic_urls);
    if (thumbs != null) {
        // json
        tweet.put(pic_urls, thumbs.toString());
    }
    tweet.put(thumbnail_pic, json.optString(thumbnail_pic));
    tweet.put(bmiddle_pic, json.optString(bmiddle_pic));
    tweet.put(original_pic, json.optString(original_pic));
    // ???
    if (json.has(retweeted_status)) {
        tweet.put(retweeted_status, json.optJSONObject(retweeted_status).toString());
    }
    // 
    if (json.has(User.SINGLE)) {
        tweet.put(uid, json.optJSONObject(User.SINGLE).optLong(Constants.ID));
    } else if (json.has(uid)) {
        tweet.put(uid, json.optLong(uid));
    }
    tweet.put(reposts_count, json.optInt(reposts_count));
    tweet.put(comments_count, json.optInt(comments_count));
    tweet.put(attitudes_count, json.optInt(attitudes_count));
    return tweet;
}

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

/**
 * Fills a Poll instance from JSONObject.
 *//*  w ww  . ja  va  2s  . c o  m*/
public VKApiPoll parse(JSONObject source) {
    id = source.optInt("id");
    owner_id = source.optInt("owner_id");
    created = source.optLong("created");
    question = source.optString("question");
    votes = source.optInt("votes");
    answer_id = source.optInt("answer_id");
    answers = new VKList<Answer>(source.optJSONArray("answers"), Answer.class);
    return this;
}

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

/**
 * Creates a PhotoAlbum instance from JSONObject.
 *///from   ww  w. j  av  a  2s . c  o m
public VKApiPhotoAlbum parse(JSONObject from) {
    id = from.optInt("id");
    thumb_id = from.optInt("thumb_id");
    owner_id = from.optInt("owner_id");
    title = from.optString("title");
    description = from.optString("description");
    created = from.optLong("created");
    updated = from.optLong("updated");
    size = from.optInt("size");
    can_upload = ParseUtils.parseBoolean(from, "can_upload");
    thumb_src = from.optString("thumb_src");
    if (from.has("privacy")) {
        privacy = from.optInt("privacy");
    } else {
        privacy = VKPrivacy.parsePrivacy(from.optJSONObject("privacy_view"));
    }
    JSONArray sizes = from.optJSONArray("sizes");
    if (sizes != null) {
        photo.fill(sizes);
    } else {
        photo.add(VKApiPhotoSize.create(COVER_S, 75, 55));
        photo.add(VKApiPhotoSize.create(COVER_M, 130, 97));
        photo.add(VKApiPhotoSize.create(COVER_X, 432, 249));
        photo.sort();
    }
    return this;
}