Java Code Examples for com.socks.jiandan.net.JSONParser

The following examples show how to use com.socks.jiandan.net.JSONParser. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JianDan_OkHttpWithVolley   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 2
Source Project: JianDan   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 3
Source Project: JianDan_OkHttp   Source File: JokeParser.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<Joke> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;

    try {
        String jsonStr = response.body().string();
        jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();
        return (ArrayList<Joke>) JSONParser.toObject(jsonStr,
                new TypeToken<ArrayList<Joke>>() {
                }.getType());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 4
Source Project: JianDan_OkHttp   Source File: PictureParser.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
public ArrayList<Picture> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;

    try {
        String jsonStr = response.body().string();
        jsonStr = new JSONObject(jsonStr).getJSONArray("comments").toString();
        return (ArrayList<Picture>) JSONParser.toObject(jsonStr,
                new TypeToken<ArrayList<Picture>>() {
                }.getType());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 5
Source Project: JianDan_OkHttp   Source File: PictureCache.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 根据页码获取缓存数据
 *
 * @param page
 * @return
 */
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.PictureCache> query = mPictureCacheDao.queryBuilder().where(PictureCacheDao
			.Properties.Page.eq("" + page));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<Picture>();
	}

}
 
Example 6
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 7
Source Project: JianDan_OkHttpWithVolley   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 8
Source Project: JianDan_OkHttpWithVolley   Source File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 9
Source Project: JianDan_OkHttpWithVolley   Source File: JokeCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Joke> getCacheByPage(int page) {
    QueryBuilder<com.socks.greendao.JokeCache> query = mJokeCacheDao.queryBuilder().where(JokeCacheDao.Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        return (ArrayList<Joke>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Joke>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 10
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 11
Source Project: JianDan   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 12
Source Project: JianDan   Source File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 13
Source Project: JianDan   Source File: JokeCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Joke> getCacheByPage(int page) {
    QueryBuilder<com.socks.greendao.JokeCache> query = mJokeCacheDao.queryBuilder().where(JokeCacheDao.Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        return (ArrayList<Joke>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Joke>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 14
Source Project: JianDan_OkHttp   Source File: SisterCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Picture> getCacheByPage(int page) {

	QueryBuilder<com.socks.greendao.SisterCache> query = mPictureCacheDao.queryBuilder().where(SisterCacheDao
			.Properties.Page.eq(Integer.toString(page)));

	if (query.list().size() > 0) {
		return (ArrayList<Picture>) JSONParser.toObject(query.list().get(0).getResult(),
				new TypeToken<ArrayList<Picture>>() {
				}.getType());
	} else {
		return new ArrayList<>();
	}

}
 
Example 15
Source Project: JianDan_OkHttp   Source File: VideoCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Video> getCacheByPage(int page) {

    QueryBuilder<com.socks.greendao.VideoCache> query = mVideoCacheDao.queryBuilder().where(VideoCacheDao.Properties.Page.eq("" + page));
    if (query.list().size() > 0) {
        return (ArrayList<Video>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Video>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 16
Source Project: JianDan_OkHttp   Source File: JokeCache.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<Joke> getCacheByPage(int page) {
    QueryBuilder<com.socks.greendao.JokeCache> query = mJokeCacheDao.queryBuilder().where(JokeCacheDao.Properties.Page.eq("" + page));

    if (query.list().size() > 0) {
        return (ArrayList<Joke>) JSONParser.toObject(query.list().get(0).getResult(),
                new TypeToken<ArrayList<Joke>>() {
                }.getType());
    } else {
        return new ArrayList<>();
    }

}
 
Example 17
Source Project: JianDan_OkHttpWithVolley   Source File: JokeAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Joke> jokes) {

        StringBuilder sb = new StringBuilder();
        for (Joke joke : jokes) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        String url = sb.toString();
        if (url.endsWith(",")) {
            url = url.substring(0, url.length() - 1);
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(url), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                for (int i = 0; i < jokes.size(); i++) {
                    jokes.get(i).setComment_counts(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mJokes.clear();
                    //首次正常加载之后,清空之前的缓存
                    JokeCache.getInstance(mActivity).clearAllCache();
                }

                mJokes.addAll(jokes);
                notifyDataSetChanged();

                //加载完毕后缓存
                JokeCache.getInstance(mActivity).addResultCache(JSONParser.toString(jokes),
                        page);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }
        ), mActivity);

    }
 
Example 18
Source Project: JianDan_OkHttpWithVolley   Source File: FreshNewsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }
 
Example 19
Source Project: JianDan_OkHttpWithVolley   Source File: VideoAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Video> videos) {

        StringBuilder sb = new StringBuilder();
        for (Video video : videos) {
            sb.append("comment-" + video.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < videos.size(); i++) {
                    videos.get(i).setComment_count(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mVideos.clear();
                    VideoCache.getInstance(mActivity).clearAllCache();
                }

                mVideos.addAll(videos);
                notifyDataSetChanged();
                VideoCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (videos), page);
                //防止加载不到一页的情况
                if (mVideos.size() < 10) {
                    loadNextPage();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, null);
            }
        }
        ), mActivity);

    }
 
Example 20
Source Project: JianDan   Source File: JokeAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Joke> jokes) {

        StringBuilder sb = new StringBuilder();
        for (Joke joke : jokes) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        String url = sb.toString();
        if (url.endsWith(",")) {
            url = url.substring(0, url.length() - 1);
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(url), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                for (int i = 0; i < jokes.size(); i++) {
                    jokes.get(i).setComment_counts(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mJokes.clear();
                    //首次正常加载之后,清空之前的缓存
                    JokeCache.getInstance(mActivity).clearAllCache();
                }

                mJokes.addAll(jokes);
                notifyDataSetChanged();

                //加载完毕后缓存
                JokeCache.getInstance(mActivity).addResultCache(JSONParser.toString(jokes),
                        page);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                mLoadFinisCallBack.loadFinish(null);
            }
        }
        ), mActivity);

    }
 
Example 21
Source Project: JianDan   Source File: FreshNewsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }
 
Example 22
Source Project: JianDan   Source File: VideoAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void getCommentCounts(final ArrayList<Video> videos) {

        StringBuilder sb = new StringBuilder();
        for (Video video : videos) {
            sb.append("comment-" + video.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < videos.size(); i++) {
                    videos.get(i).setComment_count(response.get(i).getComments() + "");
                }

                if (page == 1) {
                    mVideos.clear();
                    VideoCache.getInstance(mActivity).clearAllCache();
                }

                mVideos.addAll(videos);
                notifyDataSetChanged();
                VideoCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (videos), page);
                //防止加载不到一页的情况
                if (mVideos.size() < 10) {
                    loadNextPage();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, null);
            }
        }
        ), mActivity);

    }
 
Example 23
Source Project: JianDan_OkHttp   Source File: FreshNewsCommentParser.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
public ArrayList<Comment4FreshNews> parse(Response response) {

    code = wrapperCode(response.code());
    if (!response.isSuccessful())
        return null;

    try {
        String resultStr = response.body().string();
        JSONObject resultObj = new JSONObject(resultStr);

        String status = resultObj.optString("status");

        if (status.equals("ok")) {
            String commentsStr = resultObj.optJSONObject("post").optJSONArray("comments")
                    .toString();
            int id = resultObj.optJSONObject("post").optInt("id");
            mCallBack.loadFinish(Integer.toString(id));

            ArrayList<Comment4FreshNews> comment4FreshNewses = (ArrayList<Comment4FreshNews>) JSONParser.toObject(commentsStr,
                    new TypeToken<ArrayList<Comment4FreshNews>>() {
                    }.getType());

            Pattern pattern = Pattern.compile("\\d{7}");

            for (Comment4FreshNews comment4FreshNews : comment4FreshNewses) {
                Matcher matcher = pattern.matcher(comment4FreshNews.getContent());
                boolean isHas7Num = matcher.find();
                boolean isHasCommentStr = comment4FreshNews.getContent().contains("#comment-");
                //有回复
                if (isHas7Num && isHasCommentStr || comment4FreshNews.getParentId() != 0) {
                    ArrayList<Comment4FreshNews> tempComments = new ArrayList<>();
                    int parentId = getParentId(comment4FreshNews.getContent());
                    comment4FreshNews.setParentId(parentId);
                    getParenFreshNews(tempComments, comment4FreshNewses, parentId);
                    Collections.reverse(tempComments);
                    comment4FreshNews.setParentComments(tempComments);
                    comment4FreshNews.setFloorNum(tempComments.size() + 1);
                    comment4FreshNews.setContent(getContentWithParent(comment4FreshNews.getContent()));
                } else {
                    comment4FreshNews.setContent(getContentOnlySelf(comment4FreshNews.getContent()));
                }
            }

            Logger.d("" + comment4FreshNewses);
            return comment4FreshNewses;
        } else {
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}