欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

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 += '
['+p+'] => ' + typeof(theObj) + '
';
retStr += '
' + print_r(theObj[p]) + '
';
} else {
retStr += '
['+p+'] => ' + theObj[p] + '
';
}
}
retStr += '
';
}
return retStr;
}