Search in sources :

Example 41 with JsonSyntaxException

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

the class HomeOtherGroupTimeLineDBTask method get.

static MessageListBean get(String accountId, String groupId, int limitCount) {
    Gson gson = new Gson();
    MessageListBean result = new MessageListBean();
    int limit = limitCount > AppConfig.DEFAULT_MSG_COUNT_50 ? limitCount : AppConfig.DEFAULT_MSG_COUNT_50;
    List<MessageBean> msgList = new ArrayList<MessageBean>();
    String sql = "select * from " + HomeOtherGroupTable.HomeOtherGroupDataTable.TABLE_NAME + " where " + HomeOtherGroupTable.HomeOtherGroupDataTable.ACCOUNTID + "  = " + accountId + " and " + HomeOtherGroupTable.HomeOtherGroupDataTable.GROUPID + " =  " + groupId + " order by " + HomeOtherGroupTable.HomeOtherGroupDataTable.ID + " asc limit " + limit;
    Cursor c = getRsd().rawQuery(sql, null);
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(HomeOtherGroupTable.HomeOtherGroupDataTable.JSONDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                MessageBean value = gson.fromJson(json, MessageBean.class);
                if (!value.isMiddleUnreadItem()) {
                    value.getListViewSpannableString();
                }
                msgList.add(value);
            } catch (JsonSyntaxException e) {
                AppLogger.e(e.getMessage());
            }
        } else {
            msgList.add(null);
        }
    }
    //delete the null flag at the head positon and the end position
    for (int i = msgList.size() - 1; i >= 0; i--) {
        if (msgList.get(i) == null) {
            msgList.remove(i);
        } else {
            break;
        }
    }
    for (int i = 0; i < msgList.size(); i++) {
        if (msgList.get(i) == null) {
            msgList.remove(i);
        } else {
            break;
        }
    }
    result.setStatuses(msgList);
    c.close();
    return result;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) JsonSyntaxException(com.google.gson.JsonSyntaxException) MessageListBean(org.qii.weiciyuan.bean.MessageListBean) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Example 42 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project iosched by google.

the class SyncUserCommand method execute.

@Override
public void execute(Context context, String type, String extraData) {
    LOGI(TAG, "Received GCM message: " + type);
    int syncJitter;
    SyncData syncData = null;
    if (extraData != null) {
        try {
            Gson gson = new Gson();
            syncData = gson.fromJson(extraData, SyncData.class);
        } catch (JsonSyntaxException e) {
            LOGI(TAG, "Error while decoding extraData: " + e.toString());
        }
    }
    if (syncData != null && syncData.sync_jitter != 0) {
        syncJitter = syncData.sync_jitter;
    } else {
        syncJitter = DEFAULT_TRIGGER_SYNC_DELAY;
    }
    scheduleSync(context, syncJitter);
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson)

Example 43 with JsonSyntaxException

use of com.google.gson.JsonSyntaxException in project MusicDNA by harjot-oberai.

the class Genius method search.

public static ArrayList<Lyrics> search(String query) {
    ArrayList<Lyrics> results = new ArrayList<>();
    query = Normalizer.normalize(query, Normalizer.Form.NFD).replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
    JsonObject response = null;
    try {
        URL queryURL = new URL(String.format("http://api.genius.com/search?q=%s", URLEncoder.encode(query, "UTF-8")));
        Connection connection = Jsoup.connect(queryURL.toExternalForm()).header("Authorization", "Bearer " + Config.GENIUS).timeout(0).ignoreContentType(true);
        Document document = connection.userAgent(Net.USER_AGENT).get();
        response = new JsonParser().parse(document.text()).getAsJsonObject();
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (response == null || response.getAsJsonObject("meta").get("status").getAsInt() != 200)
        return results;
    JsonArray hits = response.getAsJsonObject("response").getAsJsonArray("hits");
    int processed = 0;
    while (processed < hits.size()) {
        JsonObject song = hits.get(processed).getAsJsonObject().getAsJsonObject("result");
        String artist = song.getAsJsonObject("primary_artist").get("name").getAsString();
        String title = song.get("title").getAsString();
        String url = "http://genius.com/songs/" + song.get("id").getAsString();
        Lyrics l = new Lyrics(Lyrics.SEARCH_ITEM);
        l.setArtist(artist);
        l.setTitle(title);
        l.setURL(url);
        l.setSource("Genius");
        results.add(l);
        processed++;
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jsoup.Connection) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) URL(java.net.URL) JsonArray(com.google.gson.JsonArray) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonParser(com.google.gson.JsonParser)

Example 44 with JsonSyntaxException

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

the class MyStatusDBTask method getPosition.

private static TimeLinePosition getPosition(String accountId) {
    String sql = "select * from " + MyStatusTable.TABLE_NAME + " where " + MyStatusTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    while (c.moveToNext()) {
        String json = c.getString(c.getColumnIndex(MyStatusTable.TIMELINEDATA));
        if (!TextUtils.isEmpty(json)) {
            try {
                TimeLinePosition value = gson.fromJson(json, TimeLinePosition.class);
                c.close();
                return value;
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    c.close();
    return TimeLinePosition.empty();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) TimeLinePosition(org.qii.weiciyuan.bean.android.TimeLinePosition) Cursor(android.database.Cursor)

Example 45 with JsonSyntaxException

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

the class MyStatusDBTask method updatePosition.

private static void updatePosition(TimeLinePosition position, String accountId) {
    String sql = "select * from " + MyStatusTable.TABLE_NAME + " where " + MyStatusTable.ACCOUNTID + "  = " + accountId;
    Cursor c = getRsd().rawQuery(sql, null);
    Gson gson = new Gson();
    if (c.moveToNext()) {
        try {
            String[] args = { accountId };
            ContentValues cv = new ContentValues();
            cv.put(MyStatusTable.TIMELINEDATA, gson.toJson(position));
            getWsd().update(MyStatusTable.TABLE_NAME, cv, MyStatusTable.ACCOUNTID + "=?", args);
        } catch (JsonSyntaxException e) {
        }
    } else {
        ContentValues cv = new ContentValues();
        cv.put(MyStatusTable.ACCOUNTID, accountId);
        cv.put(MyStatusTable.TIMELINEDATA, gson.toJson(position));
        getWsd().insert(MyStatusTable.TABLE_NAME, MyStatusTable.ID, cv);
    }
}
Also used : ContentValues(android.content.ContentValues) JsonSyntaxException(com.google.gson.JsonSyntaxException) Gson(com.google.gson.Gson) Cursor(android.database.Cursor)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)152 Gson (com.google.gson.Gson)103 HashMap (java.util.HashMap)40 Cursor (android.database.Cursor)33 ArrayList (java.util.ArrayList)26 IOException (java.io.IOException)24 MessageBean (org.qii.weiciyuan.bean.MessageBean)16 GsonBuilder (com.google.gson.GsonBuilder)15 BadRequestException (co.cask.cdap.common.BadRequestException)14 InputStreamReader (java.io.InputStreamReader)14 ContentValues (android.content.ContentValues)12 TimeLinePosition (org.qii.weiciyuan.bean.android.TimeLinePosition)12 Reader (java.io.Reader)10 Type (java.lang.reflect.Type)10 FileReader (java.io.FileReader)9 Path (javax.ws.rs.Path)9 CommentBean (org.qii.weiciyuan.bean.CommentBean)9 UserBean (org.qii.weiciyuan.bean.UserBean)9 JsonObject (com.google.gson.JsonObject)8 List (java.util.List)8