javascript仿php的print_r函数输出json数据_javascript技巧
程序员文章站
2022-05-11 19:06:42
...
复制代码 代码如下:
//theOb(json数据)
function print_r(theObj) {
var retStr = '';
if (typeof theObj == 'object') {
retStr += '
';
for (var p in theObj) {
if (typeof theObj[p] == 'object') {
retStr += '
retStr += '
} else {
retStr += '
}
}
retStr += '
'; for (var p in theObj) {
if (typeof theObj[p] == 'object') {
retStr += '
['+p+'] => ' + typeof(theObj) + '
'; retStr += '
' + print_r(theObj[p]) + '
'; } else {
retStr += '
['+p+'] => ' + theObj[p] + '
'; }
}
retStr += '
}
return retStr;
}
推荐阅读
-
用js写了一个类似php的print_r输出换行功能_javascript技巧
-
javascript仿php的print_r函数输出json数据_javascript技巧
-
用Json实现PHP与JavaScript间数据交换的方法详解_php技巧
-
javascript仿php的print_r函数输出json数据_javascript技巧
-
用nodejs实现PHP的print_r函数代码_javascript技巧
-
用js写了一个类似php的print_r输出换行功能_javascript技巧
-
用Json实现PHP与JavaScript间数据交换的方法详解_php技巧
-
用nodejs实现PHP的print_r函数代码_javascript技巧