Search in sources :

Example 6 with JSONArray

use of weibo4j.org.json.JSONArray in project twitter-2-weibo by rjyo.

the class User method constructIds.

public static String[] constructIds(Response res) throws WeiboException {
    try {
        JSONArray list = res.asJSONObject().getJSONArray("ids");
        String temp = list.toString().substring(1, list.toString().length() - 1);
        String[] ids = temp.split(",");
        return ids;
    } catch (JSONException jsone) {
        throw new WeiboException(jsone.getMessage() + ":" + jsone.toString(), jsone);
    }
}
Also used : JSONArray(weibo4j.org.json.JSONArray) JSONException(weibo4j.org.json.JSONException)

Example 7 with JSONArray

use of weibo4j.org.json.JSONArray in project twitter-2-weibo by rjyo.

the class Comment method constructWapperComments.

public static CommentWapper constructWapperComments(Response res) throws WeiboException {
    //asJSONArray();
    JSONObject json = res.asJSONObject();
    try {
        JSONArray comments = json.getJSONArray("comments");
        int size = comments.length();
        List<Comment> comment = new ArrayList<Comment>(size);
        for (int i = 0; i < size; i++) {
            comment.add(new Comment(comments.getJSONObject(i)));
        }
        long previousCursor = json.getLong("previous_curosr");
        long nextCursor = json.getLong("next_cursor");
        long totalNumber = json.getLong("total_number");
        String hasvisible = json.getString("hasvisible");
        return new CommentWapper(comment, previousCursor, nextCursor, totalNumber, hasvisible);
    } catch (JSONException jsone) {
        throw new WeiboException(jsone);
    }
}
Also used : JSONObject(weibo4j.org.json.JSONObject) JSONArray(weibo4j.org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(weibo4j.org.json.JSONException)

Example 8 with JSONArray

use of weibo4j.org.json.JSONArray in project twitter-2-weibo by rjyo.

the class Emotion method constructEmotions.

public static List<Emotion> constructEmotions(Response res) throws WeiboException {
    try {
        JSONArray list = res.asJSONArray();
        int size = list.length();
        List<Emotion> emotions = new ArrayList<Emotion>(size);
        for (int i = 0; i < size; i++) {
            emotions.add(new Emotion(list.getJSONObject(i)));
        }
        return emotions;
    } catch (JSONException jsone) {
        throw new WeiboException(jsone);
    } catch (WeiboException te) {
        throw te;
    }
}
Also used : JSONArray(weibo4j.org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(weibo4j.org.json.JSONException)

Example 9 with JSONArray

use of weibo4j.org.json.JSONArray in project twitter-2-weibo by rjyo.

the class FavoritesTag method constructTags.

public static List<FavoritesTag> constructTags(Response res) throws WeiboException {
    try {
        JSONArray list = res.asJSONArray();
        int size = list.length();
        List<FavoritesTag> tags = new ArrayList<FavoritesTag>(size);
        for (int i = 0; i < size; i++) {
            tags.add(new FavoritesTag(list.getJSONObject(i)));
        }
        return tags;
    } catch (JSONException jsone) {
        throw new WeiboException(jsone);
    } catch (WeiboException te) {
        throw te;
    }
}
Also used : JSONArray(weibo4j.org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(weibo4j.org.json.JSONException)

Example 10 with JSONArray

use of weibo4j.org.json.JSONArray in project twitter-2-weibo by rjyo.

the class Status method constructWapperStatus.

public static StatusWapper constructWapperStatus(Response res) throws WeiboException {
    //asJSONArray();
    JSONObject jsonStatus = res.asJSONObject();
    JSONArray statuses = null;
    try {
        if (!jsonStatus.isNull("statuses")) {
            statuses = jsonStatus.getJSONArray("statuses");
        }
        if (!jsonStatus.isNull("reposts")) {
            statuses = jsonStatus.getJSONArray("reposts");
        }
        int size = statuses.length();
        List<Status> status = new ArrayList<Status>(size);
        for (int i = 0; i < size; i++) {
            status.add(new Status(statuses.getJSONObject(i)));
        }
        long previousCursor = jsonStatus.getLong("previous_curosr");
        long nextCursor = jsonStatus.getLong("next_cursor");
        long totalNumber = jsonStatus.getLong("total_number");
        String hasvisible = jsonStatus.getString("hasvisible");
        return new StatusWapper(status, previousCursor, nextCursor, totalNumber, hasvisible);
    } catch (JSONException jsone) {
        throw new WeiboException(jsone);
    }
}
Also used : JSONObject(weibo4j.org.json.JSONObject) JSONArray(weibo4j.org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(weibo4j.org.json.JSONException)

Aggregations

JSONArray (weibo4j.org.json.JSONArray)16 JSONException (weibo4j.org.json.JSONException)16 ArrayList (java.util.ArrayList)13 JSONObject (weibo4j.org.json.JSONObject)5 Date (java.util.Date)2 Iterator (java.util.Iterator)1