Example usage for org.json JSONObject getLong

List of usage examples for org.json JSONObject getLong

Introduction

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

Prototype

public long getLong(String key) throws JSONException 

Source Link

Document

Get the long value associated with a key.

Usage

From source file:com.citrus.mobile.OauthToken.java

private boolean hasExpired(JSONObject token) {
    try {//from w  w w. jav a  2  s .c  o  m
        return token.getLong("expiry") <= (new Date().getTime() / 1000l);
    } catch (JSONException e) {
        return true;
    }
}

From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEP070402DataImpl.java

public static EEP070402DataImpl constructDataFromRecord(JSONObject lastKnownData) {
    if (lastKnownData == null)
        return new EEP070402DataImpl(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, null);

    try {/*from w  w w.  j  a  v  a2s  .  c  om*/
        float supplyVoltage = (float) lastKnownData.getDouble("supplyVoltage");
        float temperature = (float) lastKnownData.getDouble("temperature");
        float relativeHumidity = (float) lastKnownData.getDouble("relativeHumidity");
        Date date = new Date(lastKnownData.getLong("date"));

        return new EEP070402DataImpl(supplyVoltage, temperature, relativeHumidity, date);
    } catch (JSONException e) {
        Logger.error(LC.gi(), null,
                "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !",
                e);
        return new EEP070402DataImpl(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, null);
    }
}

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

private List<Comment> getComments(String content) throws WeiboException {
    List<Comment> comments = new ArrayList<Comment>();
    try {/*from w  w w. j  a va 2s  . c o m*/
        JSONArray jarray = new JSONArray(content);
        for (int i = 0; i < jarray.length(); i++) {
            Comment comment = new Comment();
            JSONObject json = jarray.getJSONObject(i);
            comment.setCreated_at(new Date(json.getString("created_at")));
            //            comment.setFavorited(json.getBoolean("favorited"));
            comment.setId(json.getLong("id"));
            //             comment.setSource(json.getString("source"));    
            //             comment.setStatus((Status) json.get("retweeted_status"));

            comment.setStatus(getStatus(json.getString("status")));

            comment.setText(json.getString("text"));
            //             comment.setTruncated(json.getBoolean("truncated"));
            //             comment.setUser((User) json.get("user"));

            //               Log.e("Weibo_comment user",  "Is NULL??");
            if (!json.isNull("user")) {
                //                  Log.e("Weibo",  "User is not null");
                String user_rlt = json.getString("user");
                User user = getUser(user_rlt);
                comment.setUser(user);
                //                  Log.e("ScreenName", user.getScreen_name());
            }

            comments.add(comment); //Add in List<>
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return comments;
}

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

/**
 *  //www .  j av  a  2s. c  o m
 * JSON  status
 * @throws WeiboException 
 */
private List<Status> getStatusList(String content) throws WeiboException {
    List<Status> statuses = new ArrayList<Status>();
    try {
        //       content = publicTimeline(weibo, Weibo.APP_KEY, since_id, max_id, count, base_app);
        JSONArray jarray = new JSONArray(content);
        for (int i = 0; i < jarray.length(); i++) { //
            Status status = new Status();
            JSONObject json = jarray.getJSONObject(i);
            //             status.setBmiddle_pic(json.getString("bmiddle_pic"));
            status.setCreated_at(new Date(json.getString("created_at")));
            status.setFavorited(json.getBoolean("favorited"));
            status.setId(json.getLong("id"));
            //Long  String
            if (!json.isNull("in_reply_to_screen_name"))
                status.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name"));
            else
                status.setIn_reply_to_screen_name(json.getString(null));

            if (!json.isNull("in_reply_to_status_id"))
                status.setIn_reply_to_status_id(json.getString("in_reply_to_status_id"));
            else
                status.setIn_reply_to_status_id(json.getString(null));

            if (!json.isNull("in_reply_to_user_id"))
                status.setIn_reply_to_user_id(json.getString("in_reply_to_user_id"));
            else
                status.setIn_reply_to_user_id(json.getString(null));

            //             status.setOriginal_pic(json.getString("original_pic"));
            status.setSource(json.getString("source"));
            //             status.setRetweetedStatus((Status) json.get("retweeted_status"));
            if (!json.isNull("retweeted_status")) {
                String retweeted_rlt = json.getString("retweeted_status");
                Status retweeted_status = getStatus(retweeted_rlt);
                status.setRetweetedStatus(retweeted_status);
            }

            status.setText(json.getString("text"));
            //             status.setThumbnail_pic(json.getString("thumbnail_pic"));
            status.setTruncated(json.getBoolean("truncated"));
            //             status.setUser((User) json.get("user"));
            if (!json.isNull("user")) {
                String user_rlt = json.getString("user");
                User user = getUser(user_rlt);
                status.setUser(user);
            }

            statuses.add(status); //Add in List<>
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return statuses;
}

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

/**
 *   JSON  status/*  w  w  w.j av  a  2s.com*/
 * @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 {//from   w  ww.ja va2  s. c  o 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  va 2 s .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 {/*from  ww w.jav  a 2s .c o m*/
        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

/**
 * POST//  w  ww .  j  a  va2 s. c o  m
 * @param cid  int64   ID
 * @param comment URLEncode,140
 * @param id ID
 * @param without_mention @<br>
 * 0@.0.
 * 
 */
public Comment postReply(Weibo weibo, Long cid, String comment, Long id, int without_mention) {
    Comment comments = new Comment();
    try {
        JSONObject json = new JSONObject(reply(weibo, cid, comment, id, without_mention));
        comments.setCreated_at(new Date(json.getString("created_at")));
        //            comments.setFavorited(json.getBoolean("favorited"));
        comments.setId(json.getLong("id"));
        //             comments.setSource(json.getString("source"));    
        //             comments.setStatus((Status) json.get("retweeted_status"));
        if (!json.isNull("retweeted_status")) {
            String retweeted_rlt = json.getString("retweeted_status");
            Status retweeted_status = getStatus(retweeted_rlt);
            comments.setStatus(retweeted_status);
        }
        comments.setText(json.getString("text"));
        //             comments.setTruncated(json.getBoolean("truncated"));
        //             comments.setUser((User) json.get("user"));

        if (!json.isNull("user")) {
            String user_rlt = json.getString("user");
            User user = getUser(user_rlt);
            comments.setUser(user);
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (WeiboException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return comments;
}

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

/**
 * n/* ww w .  ja v a2s  .c  o m*/
 * 20  
 * @param ids  ID 
 */
public List<Count> getCount(Long[] ids) throws JSONException {
    String content;
    List<Count> result = new ArrayList<Count>();

    try {

        content = counts(ids);
        Log.e("content", content);

        JSONArray jarray = new JSONArray(content);

        for (int i = 0; i < jarray.length(); i++) {
            JSONObject json = jarray.getJSONObject(i);
            Count count = new Count();
            count.setComments(json.getInt("comments"));
            count.setRt(json.getInt("rt"));
            count.setId(json.getLong("id"));

            result.add(count);
        }
    } catch (WeiboException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}