简体   繁体   English

使用Jquery进行JSON解析

[英]JSON parse using Jquery

I'm trying to parse a JSON string using $.getJSON. 我正在尝试使用$ .getJSON解析JSON字符串。 The string structure is this: 字符串结构是这样的:

{"status":"1","dati":[{"id":"259","temperatura":"27.5\u00b0C","localita":"Perugia (PG)","distanza":"8.94","altitudine":"493","pioggia":"0.0","pressione":"1013.5","vento":"12.9","minima":"15.9","massima":"27.5","orario":"12\/07\/2013 17.35","url":"http:\/\/www.perugiameteo.it\/standardpage.aspx?id=56","webcam":"http:\/\/www.perugiameteo.net\/webcam\/webcam.jpg","raffica":"30.6","rate":"0.0"}]}

and this is the code that I'm trying to use, but without success (I obtain an undefined value) 这是我尝试使用的代码,但是没有成功(我获得了未定义的值)

<ul id="groups"></ul>

<script type='text/javascript'>
    $(document).ready(function() {
       var $grouplist = $('#groups');
       $.getJSON("URL_FILE", function(MyData){
           $.each(MyData.dati, function() {
           $('<li>' + this.localita + '</li>').appendTo($grouplist);
           });
       });
    });
</script>

Any helps? 有帮助吗? Thanks in advance! 提前致谢!

Since you have proven via jsfiddles in the comments that it works with local data, then it is obviously an AJAX issue. 由于您已经通过jsfiddles在注释中证明了它可用于本地数据,因此显然是AJAX问题。

Install Fiddler so you can watch the traffic and make the request yourself through Fiddler. 安装Fiddler,以便您可以观察流量并通过Fiddler自己提出请求。 It will show the payload being returned. 它将显示返回的有效负载。

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

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