I am using jQuery. I am dealing with JSON object and time and again I need to look at the data. I do alert(data) and I get nothing useful.
In the Prototype world they have inspect method which is highly useful. inspect method in Prototype
I am looking for equivalent method in jQuery. I looked at the API and couldn't find anything. I am sure someone would have developed some plugin to solve this problem.
You can use the jQuery.param
function, which will format it into a querystring format.
alert(jQuery.param({ width:1680, height:1050 }));
// shows "width=1680&height=1050"
I have the best result with http://www.JSON.org/json2.js. As the docs say:
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.
Just include the library and call alert(JSON.stringify(data))
to see a legible representation of your object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With