Prototype有hash.inspect()方法。 jQuery世界中的等价物是什么?

我正在使用jQuery。 我正在处理JSON对象,我需要一次又一次地查看数据。 我做警报(数据),我什么都没有用。

在Prototype世界中,他们拥有非常有用的检查方法。 检查原型中的方法

我正在寻找jQuery中的等效方法。 我查看了API,找不到任何东西。 我相信有人会开发一些插件来解决这个问题。

我用http://www.JSON.org/json2.js得到了最好的结果。 正如文档所说:

JSON.stringify(value, replacer, space) value any JavaScript value, usually an object or array. replacer an optional parameter that determines how object values are stringified for objects. It can be a function or an array of strings. space an optional parameter that specifies the indentation of nested structures. If it is omitted, the text will be packed without extra whitespace. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or ' '), it contains the characters used to indent at each level. 

只需包含库并调用alert(JSON.stringify(data))即可查看对象的清晰表示。

如果您使用的是FireBug ,则可以调用console.log(myJsonObject) ,FireBug将在控制台中为您提供一个很好的JSON对象显示。

您可以使用jQuery.param函数,该函数将其格式化为查询字符串格式。

 alert(jQuery.param({ width:1680, height:1050 })); // shows "width=1680&height=1050" 

此外,firefox和其他优秀的浏览器支持对象和函数的Source()方法。

alert(foo.toSource())

你也可以这样做…

 $.getJSON("some/url/here", { /* optional params */ }, function(json) { alert("get returned: " + json.toString()); });