logcat 格式化输出json
来源:互联网 发布:光纤网络延迟高怎么办 编辑:程序博客网 时间:2024/05/29 05:58
/** * json格式化工具 * @author Young * */public class JsonFormat {/** * 默认每次缩进两个空格 */private static final String empty=" ";public static String format(String json){try {int empty=0;char[]chs=json.toCharArray();StringBuilder stringBuilder=new StringBuilder();for (int i = 0; i < chs.length;) {//若是双引号,则为字符串,下面if语句会处理该字符串if (chs[i]=='\"') {stringBuilder.append(chs[i]);i++;//查找字符串结束位置for ( ; i < chs.length;) {//如果当前字符是双引号,且前面有连续的偶数个\,说明字符串结束if ( chs[i]=='\"'&&isDoubleSerialBackslash(chs,i-1)) {stringBuilder.append(chs[i]);i++;break;} else{stringBuilder.append(chs[i]);i++;}}}else if (chs[i]==',') {stringBuilder.append(',').append('\n').append(getEmpty(empty));i++;}else if (chs[i]=='{'||chs[i]=='[') {empty++;stringBuilder.append(chs[i]).append('\n').append(getEmpty(empty));i++;}else if (chs[i]=='}'||chs[i]==']') {empty--;stringBuilder.append('\n').append(getEmpty(empty)).append(chs[i]);i++;}else {stringBuilder.append(chs[i]);i++;}}return stringBuilder.toString();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();return json;}}private static boolean isDoubleSerialBackslash(char[] chs, int i) {int count=0;for (int j = i; j >-1; j--) {if (chs[j]=='\\') {count++;}else{return count%2==0;}}return count%2==0;}/** * 缩进 * @param count * @return */private static String getEmpty(int count){StringBuilder stringBuilder=new StringBuilder();for (int i = 0; i < count; i++) {stringBuilder.append(empty) ;}return stringBuilder.toString();}}
0 0
- logcat 格式化输出json
- 页面Json格式化输出
- json 格式化输出
- JSON格式化输出
- JSON格式化输出
- 格式化JSON输出
- golang json格式化输出
- 格式化输出json数据
- json 格式化输出
- Json格式化输出
- JSON格式化输出
- android logcat输出json长度不足
- json对象格式化字符串输出
- PHP格式化输出json数据
- go json数据格式化输出
- Python进行JSON格式化输出
- logcat输出
- Android Logcat 直接输出JSON格式的数据
- PHP中CURL方法curl_setopt()函数的一些参数
- Rman 中备份归档日志时archivelog delete all input 与delete input的区别
- Android-蓝牙聊天代码解析
- vim 中删除 ^M
- cocos2dx 管理者模式
- logcat 格式化输出json
- THE MAGICIAN'S NEPHEW (auto translate)
- Broadcastreceiver components are not allowed to bind to services in android
- 时序列数据库武斗大会之TSDB名录 Part 2
- Bitmap 优化与相关知识整理
- 单例模式
- AlertDialog点击自定控件关闭
- 算法:动态规划经典题目
- Android Broadcast Security