Example usage for org.json JSONObject isNull

List of usage examples for org.json JSONObject isNull

Introduction

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

Prototype

public boolean isNull(String key) 

Source Link

Document

Determine if the value associated with the key is null or if there is no value.

Usage

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Feed> getPostCall(String friendID, int limitPost) throws EasyFacebookError {

    int flagNext = 0;
    String until = "";
    int countPost = 0;
    int numArrayElement = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    if (friendID == null)
        friendID = "me";

    String jsonResponse;/*w  ww.  ja v a  2s .c  o  m*/
    List<Feed> feedList = new ArrayList<Feed>();

    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/feed", "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countPost < limitPost || limitPost < 0); i++) {
                    feedList.add(jsonArray.getFeed(i));
                    countPost++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countPost < limitPost || limitPost < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/feed",
                                    "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }

                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countPost < limitPost || limitPost < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }
    return feedList;
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Home> getHomeCall(int limitHome) throws EasyFacebookError {
    int numArrayElement = 0;
    int flagNext = 0;
    String until = "";
    int countHome = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;/* www.  j  a  v  a  2  s .  c om*/
    List<Home> homeList = new ArrayList<Home>();
    try {

        jsonResponse = Util.openUrl("https://graph.facebook.com/me/home", "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countHome < limitHome || limitHome < 0); i++) {
                    homeList.add(jsonArray.getHome(i));
                    countHome++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countHome < limitHome || limitHome < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl("https://graph.facebook.com/me/home", "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }
                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countHome < limitHome || limitHome < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    return homeList;
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

public Comment getComment(String commentId) throws EasyFacebookError {

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;//from  w  ww  . ja  va2s. c  om
    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/" + commentId, "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        JSONSingleObjectDecode objectjson = new JSONSingleObjectDecode();
        return objectjson.getComment(jsonResponse);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

}

From source file:com.easy.facebook.android.apicall.GraphApi.java

public Events getEvent(String eventId) throws EasyFacebookError {

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    try {//w  w  w.  j ava2s  .  c o  m

        String jsonResponse = Util.openUrl("https://graph.facebook.com/" + eventId, "GET", params);

        JSONSingleObjectDecode objectjson = new JSONSingleObjectDecode();

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        return objectjson.getEvent(jsonResponse);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Events> getEventsCall(String friendID, int limitEvents) throws EasyFacebookError {
    int numArrayElement = 0;
    int flagNext = 0;
    String until = "";
    int countEvents = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    if (friendID == null)
        friendID = "me";

    String jsonResponse;/*from   ww w .  j av a  2  s.  c om*/
    List<Events> eventsList = new ArrayList<Events>();

    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/events", "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countEvents < limitEvents || limitEvents < 0); i++) {
                    eventsList.add(jsonArray.getEvent(i));
                    countEvents++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countEvents < limitEvents || limitEvents < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/events",
                                    "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }
                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countEvents < limitEvents || limitEvents < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    return eventsList;
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Person> getEventsResponseCall(String eventId, int limitEvents, String response)
        throws EasyFacebookError {
    int numArrayElement = 0;
    int flagNext = 0;
    String until = "";
    int countEvents = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;//from w  w w  . ja va  2  s  .c  o  m
    List<Person> personList = new ArrayList<Person>();
    try {

        jsonResponse = Util.openUrl("https://graph.facebook.com/" + eventId + "/" + response, "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countEvents < limitEvents || limitEvents < 0); i++) {
                    personList.add(jsonArray.getPerson(i));
                    countEvents++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countEvents < limitEvents || limitEvents < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl(
                                    "https://graph.facebook.com/" + eventId + "/" + response, "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }
                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countEvents < limitEvents || limitEvents < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    return personList;
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Person> getFriendsCall(int limitFriend) throws EasyFacebookError {
    int numArrayElement = 0;
    int flagNext = 0;
    String until = "";
    int countEvents = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;/*w w w  . ja v a 2s  .  co  m*/
    List<Person> personList = new ArrayList<Person>();
    try {

        jsonResponse = Util.openUrl("https://graph.facebook.com/me/friends", "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countEvents < limitFriend || limitFriend < 0); i++) {
                    personList.add(jsonArray.getPerson(i));
                    countEvents++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countEvents < limitFriend || limitFriend < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl("https://graph.facebook.com/me/friends", "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }
                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countEvents < limitFriend || limitFriend < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    return personList;

}

From source file:com.easy.facebook.android.apicall.GraphApi.java

private List<Group> getGroupsCall(String friendID, int limitGroups) throws EasyFacebookError {
    int numArrayElement = 0;
    int flagNext = 0;
    String until = "";
    int countGroups = 0;

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    if (friendID == null)
        friendID = "me";

    List<Group> groupsList = new ArrayList<Group>();
    try {/*from w w w  . j  a  v a  2 s.  c  om*/

        String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/groups", "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        do {

            JSONObject objectJSON = new JSONObject(jsonResponse);

            String jsonData = "";
            if (!objectJSON.isNull("data")) {
                jsonData = objectJSON.getString("data").toString();

                JSONObjectDecode jsonArray = new JSONObjectDecode(jsonData);

                numArrayElement = jsonArray.length();

                for (int i = 0; i < jsonArray.length() && (countGroups < limitGroups || limitGroups < 0); i++) {
                    groupsList.add(jsonArray.getGroup(i));
                    countGroups++;
                }

                String paging = "";
                if (!objectJSON.isNull("paging")) {
                    paging = objectJSON.getString("paging");

                    JSONObject objectnextJSON = new JSONObject(paging);
                    String next = "";
                    if (!objectnextJSON.isNull("next")) {
                        next = objectnextJSON.getString("next").toString();
                        if (!until.equals(
                                next.substring(next.lastIndexOf("until=") + 6, next.length()).toString())
                                && (countGroups < limitGroups || limitGroups < 0)) {
                            flagNext = 1;
                            until = next.substring(next.lastIndexOf("until=") + 6, next.length());
                            params = new Bundle();
                            params.putString("format", "json");
                            params.putString("access_token", facebook.getAccessToken());
                            params.putString("limit", "25");
                            params.putString("until", until);
                            jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendID + "/groups",
                                    "GET", params);

                            objectJSONErrorCheck = new JSONObject(jsonResponse);

                            if (!objectJSONErrorCheck.isNull("error")) {
                                throw new EasyFacebookError(jsonResponse);

                            }
                        } else {
                            flagNext = 0;
                        }

                    }
                }
            }
        } while (flagNext == 1 && numArrayElement > 0 && (countGroups < limitGroups || limitGroups < 0));

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }
    return groupsList;
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

public Group getGroup(String groupId) throws EasyFacebookError {

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;//from   w  w  w . java2s.co m
    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/" + groupId, "GET", params);

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        JSONSingleObjectDecode objectjson = new JSONSingleObjectDecode();

        return objectjson.getGroup(jsonResponse);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }
}

From source file:com.easy.facebook.android.apicall.GraphApi.java

public Message getMessage(String messageID) throws EasyFacebookError {

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());

    String jsonResponse;//w w w .  j  av  a2s.  c o  m
    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/" + messageID, "GET", params);

        JSONSingleObjectDecode objectjson = new JSONSingleObjectDecode();

        JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

        if (!objectJSONErrorCheck.isNull("error")) {
            throw new EasyFacebookError(jsonResponse);

        }

        return objectjson.getMessage(jsonResponse);

    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }
}