先扯两句
这部分内容原本是想写成一个附录的,不过细想起来,这两部分内容在开发中还是很好用的偷懒手段,这里也就单独开了一篇博客。
还是先上我的Git库。
MyBaseApplication (https://github.com/BanShouWeng/MyBaseApplication)
并给大家展示个神器,叫Android知识点——目录,好了,闲言少叙,下面进入正题。
正文
Log日志输出显示不完整
不知道大家在开发过程中有没有遇到过这种尴尬,那就是我们想要看打印日志信息的时候,命名日志信息全都得到了,可是当我们在Android Monitor中查看的时候,却在关键的地方戛然而止,那种感觉别提多难受了,如果不是和谐社会,真想把开发AS的找来狠狠的揍一顿。
不过转念一想,能不能打得过对方暂且不论,有找他当前在那的时间成本,我还不如想想怎么解决当前的问题,不然领导老板想揍我可不用费力找,为了那么点工资,我还真不敢还手。
功夫不负有心人,终于找到了天才哆啦梦在这篇解决AndroidStudio的logcat显示超长字符串的问题,看到人家名字起得这么专业,我这小心脏又被狠狠的暴击了一下,下面是天才哆啦梦的分析:
问题描述: 使用Log打印服务器返回的json数据时,有时候数据过长,在AndroidStudio的logcat只显示了一部分。没有完整的json体,首先最尴尬的是没法使用AndroidStudio的插件一键生成对应的数据实体了,哈哈。为了使用插件“偷懒”,我目标把数据源全部打印在logcat上。
解决思路: 首先,要知道LogCat中的每次打印的message是有上限的,原来logcat在实现上对于message的内存分配大概是4k左右.所以超过的内容都直接被丢弃了。这就是我们使用Log打印长json字符串,结果不完整的原因。我写一个工具类,用递归的思想处理这个问题。
代码部分,我做了一定的修改,显示的长度写死成最大值“3999”至于为什么没用4000,天才哆啦梦博客中说不行,我就没尝试,毕竟这部分无关大雅,其后就是参数的顺序,tag在前,显示的logContent在后,毕竟原本log的顺序就是这样,这个顺序也舒服一些。当然,这所谓的修改与没修改差别也不大,就是一个习惯的调整罢了。
private static boolean debug = true;
private static int showLength = 3999;
/**
* 分段打印出较长log文本
*
* @param logContent 打印文本
* @param tag 打印log的标记
*/
public static void info(String tag, String logContent) {
if (!debug) {
return;
}
if (logContent.length() > showLength) {
String show = logContent.substring(0, showLength);
i(tag, show);
/*剩余的字符串如果大于规定显示的长度,截取剩余字符串进行递归,否则打印结果*/
if ((logContent.length() - showLength) > showLength) {
String partLog = logContent.substring(showLength, logContent.length());
info(tag, partLog);
} else {
String printLog = logContent.substring(showLength, logContent.length());
i(tag, printLog);
}
} else {
e(tag, logContent);
}
}
这里我贴出的代码是i的,也就是information,当然也可以再封装一个error的,这部分也视个人习惯而定。其中的debug参数是为了方便日志管理,只需要在这里做一下修改,就可以控制全局日志的输出与否,避免发布的时候,个别日志没有关闭,导致信息泄漏。
//网络访问代码
@Override
public void onNext(@NonNull ResponseBody responseBody) {
try {
String responseString = responseBody.string();
Log.i("responseString", responseString);
LogUtil.info("response", responseString);
} catch (IOException e) {
e.printStackTrace();
}
}
修改前后的日志对比
//修改前
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/responseString: {"count": 10, "start": 0, "total": 250, "subjects": [{"rating": {"max": 10, "average": 9.6, "stars": "50", "min": 0}, "genres": ["\u72af\u7f6a", "\u5267\u60c5"], "title": "\u8096\u7533\u514b\u7684\u6551\u8d4e", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054521\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/17525.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/17525.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/17525.jpg"}, "name": "\u8482\u59c6\u00b7\u7f57\u5bbe\u65af", "id": "1054521"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1054534\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/34642.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/34642.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/34642.jpg"}, "name": "\u6469\u6839\u00b7\u5f17\u91cc\u66fc", "id": "1054534"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1041179\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/5837.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/5837.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/5837.jpg"}, "name": "\u9c8d\u52c3\u00b7\u5188\u987f", "id": "1041179"}], "collect_count": 1088930, "original_title": "The Shawshank Redemption", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1047973\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/230.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/230.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/230.jpg"}, "name": "\u5f17\u5170\u514b\u00b7\u5fb7\u62c9\u90a6\u7279", "id": "1047973"}], "year": "1994", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p480747492.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p480747492.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p480747492.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1292052\/", "id": "1292052"}, {"rating": {"max": 10, "average": 9.5, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u7231\u60c5", "\u540c\u6027"], "title": "\u9738\u738b\u522b\u59ec", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1003494\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/67.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/67.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/67.jpg"}, "name": "\u5f20\u56fd\u8363", "id": "1003494"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1050265\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/46345.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/46345.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/46345.jpg"}, "name": "\u5f20\u4e30\u6bc5", "id": "1050265"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1035641\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/1399268395.47.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/1399268395.47.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/1399268395.47.jpg"}, "name": "\u5de9\u4fd0", "id": "1035641"}], "collect_count": 774680, "original_title": "\u9738\u738b\u522b\u59ec", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1023040\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/750.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/750.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/750.jpg"}, "name": "\u9648\u51ef\u6b4c", "id": "1023040"}], "year": "1993", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p1910813120.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p1910813120.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster
//修改后
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: {"count": 10, "start": 0, "total": 250, "subjects": [{"rating": {"max": 10, "average": 9.6, "stars": "50", "min": 0}, "genres": ["\u72af\u7f6a", "\u5267\u60c5"], "title": "\u8096\u7533\u514b\u7684\u6551\u8d4e", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054521\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/17525.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/17525.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/17525.jpg"}, "name": "\u8482\u59c6\u00b7\u7f57\u5bbe\u65af", "id": "1054521"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1054534\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/34642.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/34642.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/34642.jpg"}, "name": "\u6469\u6839\u00b7\u5f17\u91cc\u66fc", "id": "1054534"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1041179\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/5837.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/5837.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/5837.jpg"}, "name": "\u9c8d\u52c3\u00b7\u5188\u987f", "id": "1041179"}], "collect_count": 1088930, "original_title": "The Shawshank Redemption", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1047973\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/230.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/230.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/230.jpg"}, "name": "\u5f17\u5170\u514b\u00b7\u5fb7\u62c9\u90a6\u7279", "id": "1047973"}], "year": "1994", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p480747492.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p480747492.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p480747492.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1292052\/", "id": "1292052"}, {"rating": {"max": 10, "average": 9.5, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u7231\u60c5", "\u540c\u6027"], "title": "\u9738\u738b\u522b\u59ec", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1003494\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/67.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/67.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/67.jpg"}, "name": "\u5f20\u56fd\u8363", "id": "1003494"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1050265\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/46345.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/46345.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/46345.jpg"}, "name": "\u5f20\u4e30\u6bc5", "id": "1050265"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1035641\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/1399268395.47.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/1399268395.47.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/1399268395.47.jpg"}, "name": "\u5de9\u4fd0", "id": "1035641"}], "collect_count": 774680, "original_title": "\u9738\u738b\u522b\u59ec", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1023040\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/750.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/750.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/750.jpg"}, "name": "\u9648\u51ef\u6b4c", "id": "1023040"}], "year": "1993", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p1910813120.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p1910813120.jpg", "med
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: ium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p1910813120.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1291546\/", "id": "1291546"}, {"rating": {"max": 10, "average": 9.4, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u52a8\u4f5c", "\u72af\u7f6a"], "title": "\u8fd9\u4e2a\u6740\u624b\u4e0d\u592a\u51b7", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1025182\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/8833.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/8833.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/8833.jpg"}, "name": "\u8ba9\u00b7\u96f7\u8bfa", "id": "1025182"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1054454\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/2274.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/2274.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/2274.jpg"}, "name": "\u5a1c\u5854\u8389\u00b7\u6ce2\u7279\u66fc", "id": "1054454"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1010507\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/104.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/104.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/104.jpg"}, "name": "\u52a0\u91cc\u00b7\u5965\u5fb7\u66fc", "id": "1010507"}], "collect_count": 1052117, "original_title": "L\u00e9on", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1031876\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/33301.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/33301.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/33301.jpg"}, "name": "\u5415\u514b\u00b7\u8d1d\u677e", "id": "1031876"}], "year": "1994", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p511118051.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p511118051.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p511118051.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1295644\/", "id": "1295644"}, {"rating": {"max": 10, "average": 9.4, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u7231\u60c5"], "title": "\u963f\u7518\u6b63\u4f20", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054450\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/551.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/551.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/551.jpg"}, "name": "\u6c64\u59c6\u00b7\u6c49\u514b\u65af", "id": "1054450"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1002676\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/51737.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/51737.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/51737.jpg"}, "name": "\u7f57\u5bbe\u00b7\u6000\u7279", "id": "1002676"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1031848\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/1345.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/1345.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/1345.jpg"}, "name": "\u52a0\u91cc\u00b7\u897f\u5c3c\u65af", "id": "1031848"}], "collect_count": 933376, "original_title": "Forrest Gump", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1053564\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/505.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/505.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/505.jpg"}, "name": "\u7f57\u4f2f\u7279\u00b7\u6cfd\u7c73\u5409\u65af", "id": "1053564"}], "year": "1994", "images": {"small": "https://img1.doubanio.com\/view\/movie_poster_cover
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: \/ipst\/public\/p510876377.jpg", "large": "https://img1.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p510876377.jpg", "medium": "https://img1.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p510876377.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1292720\/", "id": "1292720"}, {"rating": {"max": 10, "average": 9.5, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u559c\u5267", "\u7231\u60c5"], "title": "\u7f8e\u4e3d\u4eba\u751f", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1041004\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/26764.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/26764.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/26764.jpg"}, "name": "\u7f57\u4f2f\u6258\u00b7\u8d1d\u5c3c\u5c3c", "id": "1041004"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1000375\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/9548.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/9548.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/9548.jpg"}, "name": "\u5c3c\u53ef\u83b1\u5854\u00b7\u5e03\u62c9\u65af\u57fa", "id": "1000375"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1000368\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/45590.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/45590.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/45590.jpg"}, "name": "\u4e54\u6cbb\u00b7\u574e\u5854\u91cc\u5c3c", "id": "1000368"}], "collect_count": 518640, "original_title": "La vita \u00e8 bella", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1041004\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/26764.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/26764.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/26764.jpg"}, "name": "\u7f57\u4f2f\u6258\u00b7\u8d1d\u5c3c\u5c3c", "id": "1041004"}], "year": "1997", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p510861873.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p510861873.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p510861873.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1292063\/", "id": "1292063"}, {"rating": {"max": 10, "average": 9.2, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u52a8\u753b", "\u5947\u5e7b"], "title": "\u5343\u4e0e\u5343\u5bfb", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1023337\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/1463193210.13.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/1463193210.13.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/1463193210.13.jpg"}, "name": "\u67ca\u7460\u7f8e", "id": "1023337"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1005438\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/44986.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/44986.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/44986.jpg"}, "name": "\u5165\u91ce\u81ea\u7531", "id": "1005438"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1045797\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/18785.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/18785.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/18785.jpg"}, "name": "\u590f\u6728\u771f\u7406", "id": "1045797"}], "collect_count": 838520, "original_title": "\u5343\u3068\u5343\u5c0b\u306e\u795e\u96a0\u3057", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054439\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/616.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/616.jpg", "medium": "h
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: ttps://img3.doubanio.com\/img\/celebrity\/medium\/616.jpg"}, "name": "\u5bab\u5d0e\u9a8f", "id": "1054439"}], "year": "2001", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p1910830216.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p1910830216.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p1910830216.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1291561\/", "id": "1291561"}, {"rating": {"max": 10, "average": 9.4, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u5386\u53f2", "\u6218\u4e89"], "title": "\u8f9b\u5fb7\u52d2\u7684\u540d\u5355", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1031220\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/44906.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/44906.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/44906.jpg"}, "name": "\u8fde\u59c6\u00b7\u5c3c\u68ee", "id": "1031220"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1054393\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/1374649659.58.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/1374649659.58.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/1374649659.58.jpg"}, "name": "\u672c\u00b7\u91d1\u65af\u5229", "id": "1054393"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1006956\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/28941.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/28941.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/28941.jpg"}, "name": "\u62c9\u5c14\u592b\u00b7\u8d39\u56e0\u65af", "id": "1006956"}], "collect_count": 494993, "original_title": "Schindler's List", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054440\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/34602.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/34602.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/34602.jpg"}, "name": "\u53f2\u8482\u6587\u00b7\u65af\u76ae\u5c14\u4f2f\u683c", "id": "1054440"}], "year": "1993", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p492406163.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p492406163.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p492406163.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1295124\/", "id": "1295124"}, {"rating": {"max": 10, "average": 9.2, "stars": "45", "min": 0}, "genres": ["\u5267\u60c5", "\u7231\u60c5", "\u707e\u96be"], "title": "\u6cf0\u5766\u5c3c\u514b\u53f7", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1041029\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/470.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/470.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/470.jpg"}, "name": "\u83b1\u6602\u7eb3\u591a\u00b7\u8fea\u5361\u666e\u91cc\u5965", "id": "1041029"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1054446\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/53358.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/53358.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/53358.jpg"}, "name": "\u51ef\u7279\u00b7\u6e29\u4e1d\u83b1\u7279", "id": "1054446"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1031864\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/45186.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/45186.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/45186.jpg"}, "name": "\u6bd4\u5229\u00b7\u8d5e\u6069", "id": "1031864"}], "collect_count": 858326, "original_title": "Titanic", "subtype": "movie", "directors": [{"alt": "ht
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: tps:\/\/movie.douban.com\/celebrity\/1022571\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/33715.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/33715.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/33715.jpg"}, "name": "\u8a79\u59c6\u65af\u00b7\u5361\u6885\u9686", "id": "1022571"}], "year": "1997", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p457760035.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p457760035.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p457760035.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/1292722\/", "id": "1292722"}, {"rating": {"max": 10, "average": 9.2, "stars": "50", "min": 0}, "genres": ["\u5267\u60c5", "\u52a8\u4f5c", "\u79d1\u5e7b"], "title": "\u76d7\u68a6\u7a7a\u95f4", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1041029\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/470.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/470.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/470.jpg"}, "name": "\u83b1\u6602\u7eb3\u591a\u00b7\u8fea\u5361\u666e\u91cc\u5965", "id": "1041029"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1101703\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/3517.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/3517.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/3517.jpg"}, "name": "\u7ea6\u745f\u592b\u00b7\u9ad8\u767b-\u83b1\u7ef4\u7279", "id": "1101703"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1012520\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/118.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/118.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/118.jpg"}, "name": "\u827e\u4f26\u00b7\u4f69\u5409", "id": "1012520"}], "collect_count": 937635, "original_title": "Inception", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1054524\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/673.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/673.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/673.jpg"}, "name": "\u514b\u91cc\u65af\u6258\u5f17\u00b7\u8bfa\u5170", "id": "1054524"}], "year": "2010", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p513344864.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p513344864.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p513344864.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/3541415\/", "id": "3541415"}, {"rating": {"max": 10, "average": 9.3, "stars": "50", "min": 0}, "genres": ["\u559c\u5267", "\u7231\u60c5", "\u79d1\u5e7b"], "title": "\u673a\u5668\u4eba\u603b\u52a8\u5458", "casts": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1009535\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/13028.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/13028.jpg", "medium": "https://img1.doubanio.com\/img\/celebrity\/medium\/13028.jpg"}, "name": "\u672c\u00b7\u8d1d\u5c14\u7279", "id": "1009535"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1000389\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/1365856130.16.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/1365856130.16.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/1365856130.16.jpg"}, "name": "\u827e\u4e3d\u838e\u00b7\u5948\u7279", "id": "1000389"}, {"alt": "https:\/\/movie.douban.com\/celebrity\/1018022\/", "avatars": {"small": "https://img1.doubanio.com\/img\/celebrity\/small\/31068.jpg", "large": "https://img1.doubanio.com\/img\/celebrity\/large\/31068.jpg", "medium": "https://img
07-20 09:05:56.947 20323-20323/com.banshouweng.mybaseapplication I/response: 1.doubanio.com\/img\/celebrity\/medium\/31068.jpg"}, "name": "\u6770\u592b\u00b7\u683c\u5c14\u6797", "id": "1018022"}], "collect_count": 607729, "original_title": "WALL\u00b7E", "subtype": "movie", "directors": [{"alt": "https:\/\/movie.douban.com\/celebrity\/1036450\/", "avatars": {"small": "https://img3.doubanio.com\/img\/celebrity\/small\/1467359656.96.jpg", "large": "https://img3.doubanio.com\/img\/celebrity\/large\/1467359656.96.jpg", "medium": "https://img3.doubanio.com\/img\/celebrity\/medium\/1467359656.96.jpg"}, "name": "\u5b89\u5fb7\u9c81\u00b7\u65af\u5766\u987f", "id": "1036450"}], "year": "2008", "images": {"small": "https://img3.doubanio.com\/view\/movie_poster_cover\/ipst\/public\/p449665982.jpg", "large": "https://img3.doubanio.com\/view\/movie_poster_cover\/lpst\/public\/p449665982.jpg", "medium": "https://img3.doubanio.com\/view\/movie_poster_cover\/spst\/public\/p449665982.jpg"}, "alt": "https:\/\/movie.douban.com\/subject\/2131459\/", "id": "2131459"}], "title": "\u8c46\u74e3\u7535\u5f71Top250"}
GsonFormat
打印日志在开发过程中自然是必不可少的环节,可是即便如此,上面的日志部分也不应该放这么多的日志,随便找个例子不就好了吗?
可如果大家细心一些就会发现,上面打印出来的日志是json串,而我们在使用json的时候,习惯性网络访问结束后便用gson或者FastJson将json转换为bean对象(bean不理解的可以参见我的博客《一个Android工程的从零开始》-1前期准备),这个是大家都知道的常识了,可是这个bean的创建却是痛苦异常的过程,需要分析整个json的层次机构,还要考虑创建参数的数据类型,小的json还好说,可是上面这一坨,我是有一种要打人的冲动。
所以铺垫了这么多,终于轮到我们的GsonFormat 登场了,插件的集成过程可以参见我的博客ButterKnife以及Android ButterKnife Zelezny中Android ButterKnife Zelezny插件的集成过程。
插件集成成功之后,我们就可以好好玩玩了,首先,我们需要将之前截取成一段一段的json拼接到一起,然后alt + insert快捷键,在菜单栏中选择GsonFormat,在弹出的对话框中输入前面拼接好的json串,可以格式化查看,也可以直接点击ok,随后让我们看看有没有需要修改的数据类型,基本不需要修改,再次点击ok等待片刻就能生成我们所需要的bean对象。
附录
《一个Android工程的从零开始》- 目录