javascript - 是否有任何 javascript 函数,甚至在 jQuery 库中与 PHP print_r() 功能相同?

标签 javascript jquery function multidimensional-array printing

大家好
是否有任何 javascript 函数或者甚至在 jQuery 库 中(我想是的,因为 jQuery 有 JSON 库并且能够序列化)与 PHP print_r() function?

相同

我已经用谷歌搜索了,但我只找到了打印一维二维数组的函数。

提前致谢...
何塞·莫雷拉

编辑:
问:我为什么要问这个?
答:实际上我有一个 $.ajax() 调用接收这样的 JSON 字符串(为了保护隐私数字被编辑):

{"sms":{"92255221":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255222":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255223":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255224":{"status":true,"debug":"ok","warnmsg":"SMS Sended!!"},"92255225":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255226":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255227":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255228":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"}}}

在我的成功时:function() 我有这样的想法:

success: function(response){
                    var data = $.parseJSON(response);
                    img_ok = "<img src=\"http://www.mysite.com/images/icons/icon-ok-16.png\" />";
                    img_fail = "<img src=\"http://www.mysite.com/images/icons/icon-fail-16.png\" />";
                    for (i=0;i<=mobilenumbers.length;i++){
                        var selector = "input.client[value*="+mobilenumbers[i]+"]";
                        // Remove input checkbox
                        $(selector).remove();
                        // Replace by an image
                        if(data['sms'][mobilenumbers[i]]['status']){
                            $(selector).filter(function(){return $(this).attr("checked");}).parent().append(img_ok);
                        }else{
                            $(selector).filter(function(){return $(this).attr("checked");}).parent().append(img_fail);
                        }*/
                    } 

但是 Firebug 说 data['sms'][mobilenumbers[i]] 是未定义的...但奇怪的是第一个 data['sms'][mobilenumbers [i]]['status'] 工作正常!

最佳答案

好问题!我不知道,有兴趣看看是否有什么事情发生。

同时,一些替代方案:

  • 在打开 Firefox 的 Firebug 的同时执行 console.log(your_object) 会给您一个漂亮的、可浏览的 TreeView 。

  • 在 IE 8 的开发人员工具中也可以实现同样的功能,但要更棘手一些。参见 this question .

关于javascript - 是否有任何 javascript 函数,甚至在 jQuery 库中与 PHP print_r() 功能相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3219208/

相关文章:

javascript - NextJS _app.tsx Component 和 pageProps 应该是什么 TypeScript 类型?

javascript - 如何使 iframe 的高度始终延伸到浏览器窗口的底部?

javascript - undefined 不是 epoch js 的函数

jQuery 使用 e.target 触发点击函数

python - 如何使调用者的命名空间可用于导入函数中的 IPython 魔法?

function - 制作一个将其参数作为 :keys to another function 传递的函数

c++ - 错误 : two or more data types in declaration of main?

JavaScript:捕获 Onkeyup 事件仅有效一次

javascript - jQuery 最接近(当元素具有多个类时最接近 hasClass)

javascript - 在php服务器端使用js验证安全吗?