Java Code Examples for com.socks.jiandan.model.CommentNumber#setThread_key()

The following examples show how to use com.socks.jiandan.model.CommentNumber#setThread_key() . 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 File: Request4CommentCounts.java    From JianDan_OkHttpWithVolley with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 2
Source File: Request4CommentCounts.java    From JianDan with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}
 
Example 3
Source File: CommentCountsParser.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<CommentNumber> parse(Response response) {

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

    try {
        String body = response.body().string();
        JSONObject jsonObject = new JSONObject(body).getJSONObject("response");
        String[] comment_IDs = response.request().urlString().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }
        return commentNumbers;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 4
Source File: Request4CommentCounts.java    From JianDan_OkHttp with Apache License 2.0 5 votes vote down vote up
@Override
protected Response<ArrayList<CommentNumber>> parseNetworkResponse(NetworkResponse response) {

    try {
        String jsonStr = new String(response.data, HttpHeaderParser.parseCharset(response.headers));

        JSONObject jsonObject = new JSONObject(jsonStr).getJSONObject("response");
        String[] comment_IDs = getUrl().split("\\=")[1].split("\\,");
        ArrayList<CommentNumber> commentNumbers = new ArrayList<>();

        for (String comment_ID : comment_IDs) {

            if (!jsonObject.isNull(comment_ID)) {
                CommentNumber commentNumber = new CommentNumber();
                commentNumber.setComments(jsonObject.getJSONObject(comment_ID).getInt(CommentNumber.COMMENTS));
                commentNumber.setThread_id(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_ID));
                commentNumber.setThread_key(jsonObject.getJSONObject(comment_ID).getString(CommentNumber.THREAD_KEY));
                commentNumbers.add(commentNumber);
            } else {
                //可能会出现没有对应id的数据的情况,为了保证条数一致,添加默认数据
                commentNumbers.add(new CommentNumber("0", "0", 0));
            }
        }

        return Response.success(commentNumbers, HttpHeaderParser.parseCacheHeaders(response));

    } catch (Exception e) {
        e.printStackTrace();
        return Response.error(new ParseError(e));
    }
}