Search in sources :

Example 61 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class FriendshipsDao method executeTask.

private UserBean executeTask(String url) throws WeiboException {
    if (TextUtils.isEmpty(uid) && TextUtils.isEmpty(screen_name)) {
        AppLogger.e("uid or screen name can't be empty");
        return null;
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    if (!TextUtils.isEmpty(uid)) {
        map.put("uid", uid);
    } else {
        map.put("screen_name", screen_name);
    }
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    try {
        UserBean value = new Gson().fromJson(jsonData, UserBean.class);
        if (value != null) {
            return value;
        }
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return null;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) UserBean(org.qii.weiciyuan.bean.UserBean) HashMap(java.util.HashMap) Gson(com.google.gson.Gson)

Example 62 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class SearchDao method getStatusList.

public SearchStatusListBean getStatusList() throws WeiboException {
    String url = URLHelper.STATUSES_SEARCH;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("count", count);
    map.put("page", page);
    map.put("q", q);
    String jsonData = null;
    jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Get, url, map);
    Gson gson = new Gson();
    SearchStatusListBean value = null;
    try {
        value = gson.fromJson(jsonData, SearchStatusListBean.class);
        List<MessageBean> list = value.getItemList();
        Iterator<MessageBean> iterator = list.iterator();
        while (iterator.hasNext()) {
            MessageBean msg = iterator.next();
            //message is deleted by sina
            if (msg.getUser() == null) {
                iterator.remove();
            } else {
                msg.getListViewSpannableString();
                TimeUtility.dealMills(msg);
            }
        }
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return value;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) SearchStatusListBean(org.qii.weiciyuan.bean.SearchStatusListBean)

Example 63 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class CommentNewMsgDao method sendNewMsg.

public CommentBean sendNewMsg() throws WeiboException {
    String url = URLHelper.COMMENT_CREATE;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("id", id);
    map.put("comment", comment);
    map.put("comment_ori", comment_ori);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    Gson gson = new Gson();
    CommentBean value = null;
    try {
        value = gson.fromJson(jsonData, CommentBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return value;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 64 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class ReplyToCommentMsgDao method reply.

public CommentBean reply() throws WeiboException {
    String url = URLHelper.COMMENT_REPLY;
    Map<String, String> map = new HashMap<String, String>();
    map.put("access_token", access_token);
    map.put("id", id);
    map.put("cid", cid);
    map.put("comment", comment);
    map.put("comment_ori", comment_ori);
    map.put("without_mention", without_mention);
    String jsonData = HttpUtility.getInstance().executeNormalTask(HttpMethod.Post, url, map);
    Gson gson = new Gson();
    CommentBean value = null;
    try {
        value = gson.fromJson(jsonData, CommentBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
    }
    return value;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) CommentBean(org.qii.weiciyuan.bean.CommentBean)

Example 65 with Gson

use of com.google.gson.Gson in project weiciyuan by qii.

the class SearchTopicDao method getGSONMsgList.

public TopicResultListBean getGSONMsgList() throws WeiboException {
    String json = getMsgListJson();
    Gson gson = new Gson();
    TopicResultListBean value = null;
    try {
        value = gson.fromJson(json, TopicResultListBean.class);
    } catch (JsonSyntaxException e) {
        AppLogger.e(e.getMessage());
        return null;
    }
    if (value != null && value.getStatuses() != null && value.getStatuses().size() > 0) {
        List<MessageBean> msgList = value.getStatuses();
        Iterator<MessageBean> iterator = msgList.iterator();
        while (iterator.hasNext()) {
            MessageBean msg = iterator.next();
            if (msg.getUser() == null) {
                iterator.remove();
            } else {
                msg.getListViewSpannableString();
                TimeUtility.dealMills(msg);
            }
        }
    }
    return value;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) TopicResultListBean(org.qii.weiciyuan.bean.TopicResultListBean) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44