大家好,
是否有任何 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/