I'm new to JSON and have not been able to get the result I want. In learning, all I want to do is almost a HELLO WORLD for JSON, with the ultimate goal being to display the data in a table.
I have a JSON Call URL that gives me JSON data, and it's formatted correctly.
I have written a script to see if I can get an alert for my JSON data:
Updated
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$.getJSON("http://li93-171.members.linode.com:8080/BrokerManager/getActiveBrokerNames/?callback=?", function(data){
console.log(data);
});
</script>
Alert shown says "[object Object],[object Object]" -- I'm obviously doing something wrong. Please help!
don't use alert
use console.log(data)
with objects
if you are using chrome click control + shift + i to view your console , IE hit F12
First of all, JSON stands for JavaScript Object Notation , which means when your JSON gets received by the client, jQuery will automatically change it from a normal string to a more usable Object. That is why all you see in the alert is [object Object]
since alert can only display strings. All non-string values will be casted into strings.
alert(data);
alert(data.toString()); //both are the same
To display an Object for debugging usages, use console.log
or
$("<pre>").html(JSON.stringify(data, null, 4)).appendTo("body");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.