大家好,
是否有任何JavaScript函数或什至在jQuery库中(我想是的,因为jQuery具有JSON库并且能够序列化),它是否与PHP print_r()
函数相同?
我已经用谷歌搜索了,但是我发现只有函数可以打印一维或二维数组。
提前致谢...
何塞·莫雷拉(JoséMoreira)
编辑:
问:为什么我要问这个?
答:实际上,我有一个$.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!"}}}
在我的
success: 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);
}*/
}
但是萤火虫说
data['sms'][mobilenumbers[i]]
是不确定的...但是奇怪的是,第一个data['sms'][mobilenumbers[i]]['status']
可以正常工作! 最佳答案
好问题!我什么都不知道,有兴趣看看是否有事情发生。
同时,一些替代方案:
在打开Firefox的Firebug的同时执行console.log(your_object)
,将为您提供一个不错的可浏览树视图。
在IE 8的开发人员工具中也可以做到这一点,但是要棘手一些。请参见this question。