Getting all the data from json?
How do I get all the data from Json Output?
$.getJSON("Test.php", { Id:Id}, function(json) {
alert(json);
});
I am aware of: alert(json.name)开发者_StackOverflow
You could serialize the object again:
alert(JSON.stringify(json));
Does not make much sense to me though. If it is only for debugging, get Firebug (you can create a new profile that you will only use for developing or use Google Chrome).
If you actually want to do something with the response, then you have to access the values of the object, like
json.bar
// or
json[1].bar
But you have to know the structure of the object obviously.
You can also always loop over the properties of an object with for...in
or over an array with a for
loop.
I suppose that you dont know what values does the json object has. try this:
jQuery.each(json, function(key, value) {
//send each key with his value to the console
console.log("key", key, "value", value);
//or maybe to the documento
document.write("key: " + key + " value: " + value);
});
Also read this tutorial I understand a lot of jquery and javascript after I read it
精彩评论