Search in sources :

Example 6 with JSONException

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

the class Tag method constructTags.

public static List<Tag> constructTags(Response res) throws WeiboException {
    try {
        JSONArray list = res.asJSONArray();
        int size = list.length();
        List<Tag> tags = new ArrayList<Tag>(size);
        for (int i = 0; i < size; i++) {
            tags.add(new Tag(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 7 with JSONException

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

the class Tag method constructTag.

public static List<FavoritesTag> constructTag(Response res) throws WeiboException {
    try {
        JSONArray list = res.asJSONObject().getJSONArray("tags");
        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 8 with JSONException

use of weibo4j.org.json.JSONException 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 9 with JSONException

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

the class InitServlet method createJedisPool.

public JedisPool createJedisPool() {
    JedisPool jedisPool;
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.testOnBorrow = true;
    config.testWhileIdle = true;
    config.maxActive = 25;
    config.maxIdle = 0;
    config.minIdle = 0;
    log.debug("Jedis pool created.");
    try {
        String services = System.getenv("VCAP_SERVICES");
        if (services != null) {
            JSONObject obj = new JSONObject(services);
            obj = obj.getJSONArray("redis-2.2").getJSONObject(0).getJSONObject("credentials");
            String hostname = obj.getString("hostname");
            int port = obj.getInt("port");
            String password = obj.getString("password");
            jedisPool = new JedisPool(config, hostname, port, 0, password);
        } else {
            jedisPool = new JedisPool(config, "localhost");
            log.info("Using localhost Redis server");
        }
        return jedisPool;
    } catch (JSONException e) {
        log.error("Failed to init", e);
        return null;
    }
}
Also used : JSONObject(weibo4j.org.json.JSONObject) ServletConfig(javax.servlet.ServletConfig) JSONException(weibo4j.org.json.JSONException) JedisPool(redis.clients.jedis.JedisPool) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool)

Example 10 with JSONException

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

the class Oauth method ts.

/*
	 * 处理解析后的json解析
	 */
public String ts(String json) {
    try {
        JSONObject jsonObject = new JSONObject(json);
        access_token = jsonObject.getString("oauth_token");
        user_id = jsonObject.getString("user_id");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return access_token;
}
Also used : JSONObject(weibo4j.org.json.JSONObject) JSONException(weibo4j.org.json.JSONException)

Aggregations

JSONException (weibo4j.org.json.JSONException)20 JSONArray (weibo4j.org.json.JSONArray)16 ArrayList (java.util.ArrayList)14 JSONObject (weibo4j.org.json.JSONObject)8 Date (java.util.Date)2 WeiboException (weibo4j.model.WeiboException)2 HttpServletRouter (h2weibo.HttpServletRouter)1 DBHelper (h2weibo.model.DBHelper)1 T2WUser (h2weibo.model.T2WUser)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 Iterator (java.util.Iterator)1 ServletConfig (javax.servlet.ServletConfig)1 HttpSession (javax.servlet.http.HttpSession)1 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)1 Header (org.apache.commons.httpclient.Header)1 GenericObjectPool (org.apache.commons.pool.impl.GenericObjectPool)1 JedisPool (redis.clients.jedis.JedisPool)1 twitter4j (twitter4j)1 RequestToken (twitter4j.auth.RequestToken)1