简体   繁体   English

显示URL中的JSON数据

[英]Display JSON Data from URL

I'm new to JSON and have not been able to get the result I want. 我是JSON的新手,无法获得所需的结果。 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. 在学习中,我要做的几乎是JSON的HELLO WORLD,其最终目标是在表中显示数据。

I have a JSON Call URL that gives me JSON data, and it's formatted correctly. 我有一个提供我JSON数据的JSON调用URL,并且其格式正确。

I have written a script to see if I can get an alert for my JSON data: 我编写了一个脚本,看是否可以收到有关JSON数据的警报:

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. 显示的警报显示“ [object Object],[object Object]”-我显然做错了。 Please help! 请帮忙!

don't use alert use console.log(data) with objects 不要将alert与对象一起使用console.log(data)

if you are using chrome click control + shift + i to view your console , IE hit F12 如果您使用的是chrome点击控件 + Shift + i查看控制台,则IE按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. 首先,JSON代表JavaScript Object Notation ,这意味着当客户端接收到您的JSON时,jQuery会自动将其从普通字符串更改为更可用的Object。 That is why all you see in the alert is [object Object] since alert can only display strings. 这就是为什么您在警报中看到的都是[object Object]因为警报只能显示字符串。 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 要显示用于调试用途的对象,请使用console.log

$("<pre>").html(JSON.stringify(data, null, 4)).appendTo("body");

在此处输入图片说明

http://jsfiddle.net/DerekL/4XayF/ http://jsfiddle.net/DerekL/4XayF/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM