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.weibo.net.Weibo.java

/**
 *   JSON  status//from  w  w  w .  j av a  2 s  .  c o m
 * @throws WeiboException 
 */
private Status getStatus(String content) throws WeiboException {
    Status status = new Status();

    try {
        JSONObject json = new JSONObject(content);
        //         status.setBmiddle_pic(json.getString("bmiddle_pic"));

        int length = content.split(":").length;
        for (int i = 0; i < length; i++) {
            //            Log.e("getStatus", 
            //                  content.split(":")[i]);

        }
        status.setCreated_at(new Date(json.getString("created_at")));
        status.setFavorited(json.getBoolean("favorited"));
        status.setId(json.getLong("id"));
        status.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name"));
        status.setIn_reply_to_status_id(json.getString("in_reply_to_status_id"));
        status.setIn_reply_to_user_id(json.getString("in_reply_to_user_id"));

        //         Log.e("original_pic", json.getString("original_pic"));
        if (!json.isNull("thumbnail_pic")) {
            status.setOriginal_pic(json.getString("original_pic"));
            status.setThumbnail_pic(json.getString("thumbnail_pic"));
            status.setBmiddle_pic(json.getString("bmiddle_pic"));
        }

        status.setSource(json.getString("source"));

        status.setText(json.getString("text"));
        //         
        //         Log.e("thumbnail_pic", json.getString("thumbnail_pic"));

        status.setTruncated(json.getBoolean("truncated"));
        //         

        if (!json.isNull("retweeted_status")) {
            String retweeted_rlt = json.getString("retweeted_status");
            Status retweeted_status = getStatus(retweeted_rlt);
            status.setRetweetedStatus(retweeted_status);
        }
        //         status.setUser((User) json.get("user")); 
        String user_rlt = json.getString("user");
        if (user_rlt != null && user_rlt != "") {
            User user = getUser(user_rlt);
            status.setUser(user);
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return status;
}

From source file:com.weibo.net.Weibo.java

private List<Status> getMentions(String content) throws WeiboException {
    List<Status> mentionsList = new ArrayList<Status>();
    try {// ww w .  j a  va  2  s . co  m

        JSONArray jarray = new JSONArray(content);
        for (int i = 0; i < jarray.length(); i++) { //
            Status mention = new Status();
            JSONObject json = jarray.getJSONObject(i);
            mention.setCreated_at((new Date(json.getString("created_at"))));
            mention.setFavorited(json.getBoolean("favorited"));
            mention.setId(json.getLong("id"));
            mention.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name"));
            if (!json.isNull("in_reply_to_status_id"))
                mention.setIn_reply_to_status_id(json.getString("in_reply_to_status_id"));
            else
                mention.setIn_reply_to_status_id(null);
            if (!json.isNull("in_reply_to_user_id"))
                mention.setIn_reply_to_user_id(json.getString("in_reply_to_user_id"));
            else
                mention.setIn_reply_to_user_id(null);
            mention.setSource(json.getString("source"));
            //          mention.setRetweetedStatus((Status) json.get("retweeted_status"));

            if (!json.isNull("retweeted_status")) {
                String retweeted_rlt = json.getString("retweeted_status");
                Status retweeted_status = getStatus(retweeted_rlt);
                mention.setRetweetedStatus(retweeted_status);
            }
            mention.setText(json.getString("text"));
            mention.setTruncated(json.getBoolean("truncated"));
            //          mention.setUser((User) json.get("user")); 

            if (!json.isNull("user")) {
                String user_rlt = json.getString("user");
                User user = getUser(user_rlt);
                mention.setUser(user);
            }
            mentionsList.add(mention); //Add in List<>

        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return mentionsList;
}

From source file:com.weibo.net.Weibo.java

private List<User> getUserList(String content) throws WeiboException {
    List<User> users = new ArrayList<User>();
    try {/*from   w w  w. ja  va2s  .c o m*/
        JSONArray jarry = new JSONArray(content);
        for (int index = 0; index < jarry.length(); index++) {
            JSONObject json = jarry.getJSONObject(index);
            User user = new User();
            user.setCity(json.getLong("city"));
            user.setCreated_at(new Date(json.getString("created_at")));
            user.setDescription(json.getString("description"));
            user.setDomain(json.getString("domain"));
            user.setFavourites_count(json.getInt("favourites_count"));
            user.setFollowers_count(json.getInt("followers_count"));
            user.setFollowing(json.getBoolean("following"));
            user.setFriends_count(json.getInt("friends_count"));
            user.setGender(json.getString("gender"));
            user.setId(json.getLong("id"));
            user.setLocation(json.getString("location"));
            user.setName(json.getString("name"));
            user.setProfile_image_url(json.getString("profile_image_url"));
            user.setProvince(json.getLong("province"));
            user.setScreen_name(json.getString("screen_name"));
            user.setStatuses_count(json.getInt("statuses_count"));
            user.setUrl(json.getString("url"));
            user.setVerified(json.getBoolean("verified"));

            if (!json.isNull("retweeted_status")) {
                String retweeted_rlt = json.getString("retweeted_status");
                Status retweeted_status = getStatus(retweeted_rlt);
                user.setStatus(retweeted_status);
            }
            users.add(user);
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return users;
}

From source file:com.weibo.net.Weibo.java

private User getUser(String content) throws WeiboException {
    User user = new User();
    try {//w  w w .j ava2s. c om
        JSONObject json = new JSONObject(content);
        user.setCity(json.getLong("city"));
        user.setCreated_at(parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss z yyyy"));
        user.setId(json.getLong("id"));
        user.setDescription(json.getString("description"));
        user.setDomain(json.getString("domain"));
        user.setFavourites_count(json.getInt("favourites_count"));
        user.setFollowers_count(json.getInt("followers_count"));
        user.setFollowing(json.getBoolean("following"));
        user.setFriends_count(json.getInt("friends_count"));
        user.setGender(json.getString("gender"));
        user.setLocation(json.getString("location"));
        user.setName(json.getString("name"));
        user.setProfile_image_url(json.getString("profile_image_url"));
        user.setProvince(json.getLong("province"));
        user.setScreen_name(json.getString("screen_name"));
        user.setStatuses_count(json.getInt("statuses_count"));
        user.setUrl(json.getString("url"));
        user.setVerified(json.getBoolean("verified"));

        if (!json.isNull("retweeted_status")) {
            String retweeted_rlt = json.getString("retweeted_status");
            Status retweeted_status = getStatus(retweeted_rlt);
            user.setStatus(retweeted_status);
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return user;
}

From source file:com.weibo.net.Weibo.java

/**
 * friendships/exists /*from   www.j av a 2  s . c  om*/
 * ABABtruefalse 
 * @param user_a
 * @param user_b 
 */
public Boolean getFriendshipsExists(Long user_a, Long user_b) throws WeiboException, JSONException {
    // TODO Auto-generated method stub
    WeiboParameters bundle = new WeiboParameters();
    bundle.add("source", APP_KEY);
    bundle.add("user_a", user_a + "");
    bundle.add("user_b", user_b + "");
    String url = Weibo.SERVER + "friendships/exists.json";
    String rtn = this.request(url, bundle, Utility.HTTPMETHOD_GET, getAccessToken());
    JSONObject json = new JSONObject(rtn);
    return json.getBoolean("friends");
}

From source file:com.weibo.net.Weibo.java

/**
 * following 0   1 //from   w  w w.  java  2 s  .c o  m
 * following  followingtrue3  2
 */
public int getFriendShips_Show(Long target_id, String target_screen_name) throws WeiboException, JSONException {
    WeiboParameters bundle = new WeiboParameters();
    bundle.add("source", APP_KEY);
    if (target_id != null)
        bundle.add("target_id", target_id + "");
    if (target_screen_name != null)
        bundle.add("target_screen_name", target_screen_name);
    String url = Weibo.SERVER + "friendships/show.json";
    String rtn = this.request(url, bundle, Utility.HTTPMETHOD_GET, getAccessToken());
    JSONObject json = new JSONObject(rtn);
    JSONObject target_json = json.getJSONObject("target");
    Boolean following = target_json.getBoolean("following");
    Boolean followed_by = target_json.getBoolean("followed_by");
    int a, b;
    a = b = 0;
    if (following)
        a = 1;
    if (followed_by)
        b = 1;
    if (a == b)
        return a & b; // 0   1
    else
        return 2 + a; //ab  a13  2
}

From source file:com.weibo.net.Weibo.java

/**
 *  //from  www .  j  a  v a 2  s  .c  o  m
 * @param type 1~4  1 2@me 3
 * 4
 * @return
 * @throws WeiboException 
 * @throws JSONException 
 */
public Boolean resetCount(int type) throws WeiboException, JSONException {
    WeiboParameters bundle = new WeiboParameters();
    bundle.add("source", APP_KEY);
    bundle.add("type", type + "");
    String url = Weibo.SERVER + "statuses/reset_count.json";
    String rlt = this.request(url, bundle, Utility.HTTPMETHOD_GET,
            OAuthConstant.getInstance().getAccessToken());
    JSONObject json = new JSONObject(rlt);
    return json.getBoolean("result");
}

From source file:com.weibo.net.Weibo.java

/**
 *    //from w  ww .  ja va2  s . co m
 */
public Boolean helpTest() throws WeiboException, JSONException {
    WeiboParameters bundle = new WeiboParameters();
    bundle.add("source", APP_KEY);
    String url = Weibo.SERVER + "help/test.json";
    String rlt = this.request(url, bundle, Utility.HTTPMETHOD_GET,
            OAuthConstant.getInstance().getAccessToken());
    JSONObject json = new JSONObject(rlt);
    return json.getBoolean("ok");
}

From source file:de.fahrgemeinschaft.FahrgemeinschaftConnector.java

public boolean isReoccuring(JSONObject reoccur) throws JSONException {
    boolean isReoccuring = false;
    for (int i = 0; i < 7; i++) {
        if (reoccur.getBoolean(FahrgemeinschaftConnector.DAYS[i])) {
            isReoccuring = true;/*from  w w w  .j a  v  a 2s.  com*/
            break;
        }
    }
    return isReoccuring;
}

From source file:com.tcs.base64.Base64ImagePlugin.java

@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
    boolean result = false;
    Log.v(TAG, "execute: action=" + action);
    //        Context context = getContext();
    if (!action.equals("saveImage")) {

        callbackContext.error("Invalid action : " + action);
        result = false;/*from   ww  w.  j av a  2  s  . co m*/
    }

    try {
        Log.v(TAG, data.getString(0));
        Log.v(TAG, data.getJSONObject(1).toString());
        String b64String = data.getString(0);
        if (b64String.startsWith("data:image")) {
            b64String = b64String.substring(22);
        } else {
            b64String = data.getString(0);
        }
        JSONObject params = data.getJSONObject(1);

        //Optional parameter
        String filename = params.has("filename") ? params.getString("filename") + ".png"
                : "b64Image_" + System.currentTimeMillis() + ".png";
        String storagetype = params.has("externalStorage") ? Environment.getExternalStorageDirectory() + ""
                : getApplicationContext().getFilesDir().getAbsolutePath();
        callbackContext.error("external ==" + Environment.getExternalStorageDirectory());
        String folder = params.has("folder") ? params.getString("folder") : storagetype + "/Pictures";

        Boolean overwrite = params.has("overwrite") ? params.getBoolean("overwrite") : false;

        result = this.saveImage(b64String, filename, folder, overwrite, callbackContext);

    } catch (JSONException e) {
        Log.v(TAG, e.getMessage());
        callbackContext.error("Exception :" + e.getMessage());
        result = false;
    }
    return result;
}