如何显示来自服务响应asp.net的数据

时间:2015-07-28 11:20:00

标签: json xml api asp.net-web-api jsonp

我正在处理地震问题... here

我正在努力推动"幅度"和"价值"地震中的信息"可以在这里看到

<div id="earthquake"></div>
    <script type="text/javascript">
            $(document).ready(function () {
                $.getJSON("http://earthquake.usgs.gov/fdsnws/event/1/query?format=xml&starttime=2015-07-27&endtime=2015-07-28&minmagnitude=5", function (dataDD) {
                    console.log(tasks);
                    var tasks = dataDD.list;
                        var html = [];
                        html.push('<div>')
                        html.push(val.description)
                        html.push(val.magnitude.mag)
                        html.push('</div>')
                        $("#earthquake").append(html.join('')).css("background-color", "white");
                    });
                });
            });
        </script>

但我无法获得正确的价值,有人可以帮助......我是xml / json的新手,无法正确地将我的想法融入其中......

任何形式的帮助都将受到赞赏....

1 个答案:

答案 0 :(得分:1)

You will probably be better advised to change your call to use GeoJSON rather than XML, as this is more easily parsed and queried by JavaScript. You can do this by changing the URL to:

http://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2015-07-27&endtime=2015-07-28&minmagnitude=5

Once you have that, you should loop over the features array in the returned result, and use properties.mag for the magnitiude