json 格式化输出
来源:互联网 发布:世界时钟哪些软件好 编辑:程序博客网 时间:2024/06/05 15:57
function indent ($json) { $result = ''; $pos = 0; $strLen = strlen($json); $indentStr = ''; $newLine = "<br/>"; $prevChar = ''; $outOfQuotes = true; for ($i=0; $i<=$strLen; $i++) { // Grab the next character in the string. $char = substr($json, $i, 1); // Are we inside a quoted string? if ($char == '"' && $prevChar != '\\\\') { $outOfQuotes = !$outOfQuotes; // If this character is the end of an element, // output a new line and indent the next line. } else if(($char == '}' || $char == ']') && $outOfQuotes) { $result .= $newLine; $pos --; for ($j=0; $j<$pos; $j++) { $result .= $indentStr; } } // Add the character to the result string. $result .= $char; // If the last character was the beginning of an element, // output a new line and indent the next line. if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) { $result .= $newLine; if ($char == '{' || $char == '[') { $pos ++; } for ($j = 0; $j < $pos; $j++) { $result .= $indentStr; } } $prevChar = $char; } return $result;}
阅读全文
0 0
- 页面Json格式化输出
- json 格式化输出
- JSON格式化输出
- JSON格式化输出
- logcat 格式化输出json
- 格式化JSON输出
- golang json格式化输出
- 格式化输出json数据
- json 格式化输出
- Json格式化输出
- JSON格式化输出
- json对象格式化字符串输出
- PHP格式化输出json数据
- go json数据格式化输出
- Python进行JSON格式化输出
- json自定义格式化输出的对象
- 将JSON对象格式化输出(上篇)
- 将JSON对象格式化输出(上篇)
- Cocos2d-X游戏开发(六)
- javaWeb服务详解(含源代码,测试通过,注释) ——applicationContext.xml
- java clone方法使用详解
- redis主从复制
- TortoiseSVN设置独占锁
- json 格式化输出
- js数值四舍五入
- LintCode 405-和为零的子矩阵
- Python笔记(10)----集合、堆、双端队列
- android.content.res.Resources$NotFoundException: Resource ID XXX问题解决
- javaWeb服务详解(含源代码,测试通过,注释) ——web.xml
- HDU 2818 Building Block (带权并查集)
- Android Spanned实现TextView富文本效果(1)--文字
- 数据压缩实验五:JPEG文件解码实验分析