输出json数据,php的print_r函数可以轻松实现,下面为大家介绍下javascript也可以模仿print_r函数输出json数据,具体实现如下,感兴趣的朋友可以了解下
复制代码 代码如下:
//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;
}
以上就是javascript仿php的print_r函数输出json数据的详细内容,更多请关注0133技术站其它相关文章!