Search in sources :

Example 6 with JSONObject

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

the class Trends method jsonArrayToTrendArray.

private static Trend[] jsonArrayToTrendArray(JSONArray array) throws JSONException {
    Trend[] trends = new Trend[array.length()];
    for (int i = 0; i < array.length(); i++) {
        JSONObject trend = array.getJSONObject(i);
        trends[i] = new Trend(trend);
    }
    return trends;
}
Also used : JSONObject(weibo4j.org.json.JSONObject)

Example 7 with JSONObject

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

the class Trends method constructTrendsList.

/* package */
public static List<Trends> constructTrendsList(Response res) throws WeiboException {
    JSONObject json = res.asJSONObject();
    List<Trends> trends;
    try {
        Date asOf = parseDate(json.getString("as_of"));
        JSONObject trendsJson = json.getJSONObject("trends");
        trends = new ArrayList<Trends>(trendsJson.length());
        Iterator ite = trendsJson.keys();
        while (ite.hasNext()) {
            String key = (String) ite.next();
            JSONArray array = trendsJson.getJSONArray(key);
            Trend[] trendsArray = jsonArrayToTrendArray(array);
            if (key.length() == 19) {
                // current trends
                trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd HH:mm:ss"), trendsArray));
            } else if (key.length() == 16) {
                // daily trends
                trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd HH:mm"), trendsArray));
            } else if (key.length() == 10) {
                // weekly trends
                trends.add(new Trends(res, asOf, parseDate(key, "yyyy-MM-dd"), trendsArray));
            }
        }
        Collections.sort(trends);
        return trends;
    } catch (JSONException jsone) {
        throw new WeiboException(jsone.getMessage() + ":" + res.asString(), jsone);
    }
}
Also used : JSONObject(weibo4j.org.json.JSONObject) Iterator(java.util.Iterator) JSONArray(weibo4j.org.json.JSONArray) JSONException(weibo4j.org.json.JSONException) Date(java.util.Date)

Example 8 with JSONObject

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

the class Trends method constructTrends.

/* package */
static Trends constructTrends(Response res) throws WeiboException {
    JSONObject json = res.asJSONObject();
    try {
        Date asOf = parseDate(json.getString("as_of"));
        JSONArray array = json.getJSONArray("trends");
        Trend[] trendsArray = jsonArrayToTrendArray(array);
        return new Trends(res, asOf, asOf, trendsArray);
    } catch (JSONException jsone) {
        throw new WeiboException(jsone.getMessage() + ":" + res.asString(), jsone);
    }
}
Also used : JSONObject(weibo4j.org.json.JSONObject) JSONArray(weibo4j.org.json.JSONArray) JSONException(weibo4j.org.json.JSONException) Date(java.util.Date)

Example 9 with JSONObject

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

the class User method constructWapperUsers.

/**
	 * 
	 * @param res
	 * @return
	 * @throws WeiboException
	 */
public static UserWapper constructWapperUsers(Response res) throws WeiboException {
    //asJSONArray();
    JSONObject jsonUsers = res.asJSONObject();
    try {
        JSONArray user = jsonUsers.getJSONArray("users");
        int size = user.length();
        List<User> users = new ArrayList<User>(size);
        for (int i = 0; i < size; i++) {
            users.add(new User(user.getJSONObject(i)));
        }
        long previousCursor = jsonUsers.getLong("previous_curosr");
        long nextCursor = jsonUsers.getLong("next_cursor");
        long totalNumber = jsonUsers.getLong("total_number");
        String hasvisible = jsonUsers.getString("hasvisible");
        return new UserWapper(users, 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

JSONObject (weibo4j.org.json.JSONObject)9 JSONException (weibo4j.org.json.JSONException)8 JSONArray (weibo4j.org.json.JSONArray)5 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 HttpServletRouter (h2weibo.HttpServletRouter)1 DBHelper (h2weibo.model.DBHelper)1 T2WUser (h2weibo.model.T2WUser)1 Iterator (java.util.Iterator)1 ServletConfig (javax.servlet.ServletConfig)1 HttpSession (javax.servlet.http.HttpSession)1 GenericObjectPool (org.apache.commons.pool.impl.GenericObjectPool)1 JedisPool (redis.clients.jedis.JedisPool)1 twitter4j (twitter4j)1 RequestToken (twitter4j.auth.RequestToken)1 Account (weibo4j.Account)1 Oauth (weibo4j.Oauth)1 Weibo (weibo4j.Weibo)1 AccessToken (weibo4j.http.AccessToken)1 WeiboException (weibo4j.model.WeiboException)1