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:edu.stanford.mobisocial.dungbeetle.Helpers.java

public static void resendProfile(final Context c, final Collection<Contact> contacts, final boolean reply) {
    if (contacts.isEmpty()) {
        return;// w  ww  . ja  v  a2s  . co m
    }
    DBHelper helper = DBHelper.getGlobal(c);
    IdentityProvider ident = new DBIdentityProvider(helper);
    Log.w(TAG, "attempting to resend");
    try {
        JSONObject profileJson = new JSONObject(ident.userProfile());
        //updateProfile(c, profileJson.optString("name"), "");
        //updatePicture(c, FastBase64.decode(profileJson.optString("picture")));
        sendMessage(c, contacts,
                new DbObject(ProfileObj.TYPE, ProfileObj.json(profileJson.optString("name"), "")));
        Log.w(TAG, "string: " + profileJson.optString("picture"));
        sendMessage(c, contacts, new DbObject(ProfilePictureObj.TYPE,
                ProfilePictureObj.json(FastBase64.decode(profileJson.optString("picture")), reply)));

        Log.w(TAG, "resending profile");
    } catch (Exception e) {
    }
    ident.close();
}

From source file:com.phelps.liteweibo.model.weibo.MusicInfo.java

public static MusicInfo parse(JSONObject jsonObject) {
    if (null == jsonObject) {
        return null;
    }/*from ww w  .j  a  v  a 2s. c  o  m*/

    MusicInfo music = new MusicInfo();
    music.author = jsonObject.optString("author");
    music.title = jsonObject.optString("title");
    music.album = jsonObject.optString("album");
    music.playUrl = jsonObject.optString("playUrl");

    return music;
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitTest.java

protected JSONObject getRemoteBranch(String gitRemoteUri, int size, int i, String name)
        throws IOException, SAXException, JSONException {
    assertRemoteUri(gitRemoteUri);//from  w  w  w. j a  v  a  2  s. c  o m
    JSONObject remote = getRemote(gitRemoteUri, 1, 0, Constants.DEFAULT_REMOTE_NAME);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);

    WebRequest request = GitRemoteTest.getGetGitRemoteRequest(remoteLocation);
    WebResponse response = webConversation.getResponse(request);
    remote = waitForTask(response).getJsonData();
    assertNotNull(remote);
    assertEquals(Constants.DEFAULT_REMOTE_NAME, remote.getString(ProtocolConstants.KEY_NAME));
    assertNotNull(remote.getString(ProtocolConstants.KEY_LOCATION));
    assertEquals(Remote.TYPE, remote.getString(ProtocolConstants.KEY_TYPE));
    JSONArray refsArray = remote.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(size, refsArray.length());
    JSONObject ref = refsArray.getJSONObject(i);
    assertEquals(Constants.R_REMOTES + Constants.DEFAULT_REMOTE_NAME + "/" + name,
            ref.getString(ProtocolConstants.KEY_FULL_NAME));
    String newRefId = ref.getString(ProtocolConstants.KEY_ID);
    assertTrue(ObjectId.isId(newRefId));
    String remoteBranchLocation = ref.getString(ProtocolConstants.KEY_LOCATION);
    ref.getString(GitConstants.KEY_COMMIT);

    request = GitRemoteTest.getGetGitRemoteRequest(remoteBranchLocation);
    response = webConversation.getResponse(request);
    JSONObject remoteBranch = waitForTask(response).getJsonData();
    assertEquals(RemoteBranch.TYPE, remoteBranch.getString(ProtocolConstants.KEY_TYPE));
    assertNotNull(remoteBranch.optString(GitConstants.KEY_COMMIT));
    assertNotNull(remoteBranch.optString(GitConstants.KEY_HEAD));
    assertNotNull(remoteBranch.optString(GitConstants.KEY_DIFF));
    return remoteBranch;
}