Example usage for org.json JSONObject optString

List of usage examples for org.json JSONObject optString

Introduction

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

Prototype

public String optString(String key) 

Source Link

Document

Get an optional string associated with a key.

Usage

From source file:com.facebook.internal.FileLruCache.java

public InputStream get(String key, String contentTag) throws IOException {
    File file = new File(this.directory, Utility.md5hash(key));

    FileInputStream input = null;
    try {/*from   w w w . j a  v  a2  s . com*/
        input = new FileInputStream(file);
    } catch (IOException e) {
        return null;
    }

    BufferedInputStream buffered = new BufferedInputStream(input, Utility.DEFAULT_STREAM_BUFFER_SIZE);
    boolean success = false;

    try {
        JSONObject header = StreamHeader.readHeader(buffered);
        if (header == null) {
            return null;
        }

        String foundKey = header.optString(HEADER_CACHEKEY_KEY);
        if ((foundKey == null) || !foundKey.equals(key)) {
            return null;
        }

        String headerContentTag = header.optString(HEADER_CACHE_CONTENT_TAG_KEY, null);

        if ((contentTag == null && headerContentTag != null)
                || (contentTag != null && !contentTag.equals(headerContentTag))) {
            return null;
        }

        long accessTime = new Date().getTime();
        Logger.log(LoggingBehavior.CACHE, TAG,
                "Setting lastModified to " + Long.valueOf(accessTime) + " for " + file.getName());
        file.setLastModified(accessTime);

        success = true;
        return buffered;
    } finally {
        if (!success) {
            buffered.close();
        }
    }
}

From source file:com.melniqw.instagramsdk.UserInfo.java

public static UserInfo fromJSON(JSONObject o) throws JSONException {
    if (o == null)
        return null;
    UserInfo userInfo = new UserInfo();
    userInfo.user = User.fromJSON(o);/*  w  ww .ja  v  a2  s  .com*/
    userInfo.bio = o.optString("bio");
    userInfo.website = o.optString("website");
    JSONObject countsJSON = o.optJSONObject("counts");
    userInfo.media = countsJSON.optInt("media");
    userInfo.follows = countsJSON.optInt("follows");
    userInfo.followedBy = countsJSON.optInt("followed_by");
    return userInfo;
}

From source file:org.idaxiang.elephant.api.user.AccountApi.java

public static String getUid() {
    try {/* w ww.  j  a  v  a 2 s . c  o m*/
        JSONObject json = request(Constants.GET_UID, new WeiboParameters(), HTTP_GET);
        return json.optString("uid");
    } catch (Exception e) {
        return null;
    }
}

From source file:uguess.qucai.com.merchant.business.user.protocol.GetPublicKeyProcess.java

@Override
protected void onResult(JSONObject o) {
    //???/*  w w  w  .jav a 2  s .  c o  m*/
    int value = o.optInt("result_code");
    if (value == 0) {
        /**
         * ??
         */
        JSONObject key = o.optJSONObject("body");
        if (key != null) {
            String keyString = key.optString("public_key");
            Cache.getInstance().setPublicKey(keyString);
        } else {

        }
    }
    setProcessStatus(value);
}

From source file:uguess.qucai.com.merchant.business.user.protocol.GetPublicKeyProcess.java

public void storePublicKey(JSONObject o) {
    JSONObject key = o.optJSONObject("body");
    if (key == null && MAX_NUM > -1) {
        QucaiApplication.getInstance().getPublicKey();
        MAX_NUM--;//from www.  j  a v  a 2 s .co m
    } else if (key != null) {
        String keyString = key.optString("public_key");
        Cache.getInstance().setPublicKey(keyString);
    } else {

    }
}

From source file:com.moki.touch.models.ContentObject.java

public ContentObject(JSONObject json) {
    contentJson = json;
    url = json.optString(CONTENT_URL);
    duration = json.optString(CONTENT_DURATION);
    title = json.optString(TITLE);
}

From source file:com.umeng.community.example.CommunityApplication.java

@Override
public void onCreate() {
    super.onCreate();
    PlatformConfig.setWeixin("wx96110a1e3af63a39", "c60e3d3ff109a5d17013df272df99199");
    //RENREN?????
    //?// w  ww  . j av  a 2 s.  c om
    PlatformConfig.setSinaWeibo("275392174", "d96fb6b323c60a42ed9f74bfab1b4f7a");
    PlatformConfig.setQQZone("1104606393", "X4BAsJAVKtkDQ1zQ");
    PushAgent.getInstance(this).setDebugMode(true);
    PushAgent.getInstance(this).setMessageHandler(new UmengMessageHandler() {
        @Override
        public void dealWithNotificationMessage(Context arg0, UMessage msg) {
            // ,????
            super.dealWithNotificationMessage(arg0, msg);
            Log.e("", "### ???");
        }
    });
    PushAgent.getInstance(this).setNotificationClickHandler(new UHandler() {
        @Override
        public void handleMessage(Context context, UMessage uMessage) {
            com.umeng.comm.core.utils.Log.d("notifi", "getting message");
            try {
                JSONObject jsonObject = uMessage.getRaw();
                String feedid = "";
                if (jsonObject != null) {
                    com.umeng.comm.core.utils.Log.d("json", jsonObject.toString());
                    JSONObject extra = uMessage.getRaw().optJSONObject("extra");
                    feedid = extra.optString(Constants.FEED_ID);
                }
                Class myclass = Class.forName(uMessage.activity);
                Intent intent = new Intent(context, myclass);
                Bundle bundle = new Bundle();
                bundle.putString(Constants.FEED_ID, feedid);
                intent.putExtras(bundle);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            } catch (Exception e) {
                com.umeng.comm.core.utils.Log.d("class", e.getMessage());
            }
        }
    });
}

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

@Override
public boolean performAction(JSONObject jObj) {
    this.version = jObj.optString("version");
    return true;/*from   w  w  w  . ja  v  a 2  s  . com*/
}

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

private static Feed parseFeed(JSONObject e) {
    String faviconLink = e.optString("faviconLink");
    if (faviconLink != null)
        if (faviconLink.equals("null") || faviconLink.trim().equals(""))
            faviconLink = null;/*from  www .  j av a2  s. c om*/

    Feed feed = new Feed();
    feed.setId(e.optLong("id"));
    feed.setFeedTitle(e.optString("title"));
    feed.setFolderId(e.optLong("folderId"));
    feed.setFaviconUrl(faviconLink);

    return feed;
}

From source file:org.schedulesdirect.grabber.Grabber.java

private boolean logoCacheInvalid(JSONObject station) throws JSONException, IOException {
    JSONObject logo = station.optJSONObject("logo");
    if (logo != null) {
        String callsign = station.getString("callsign");
        String cached = logoCache.optString(callsign, null);
        if (cached != null)
            return !cached.equals(logo.optString("md5"));
    }//from  w  ww .  j  ava 2  s .  co m
    return true;
}