0

我如何使用 jQuery.getJSON() 获取此 URL 的数据?

http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts

如果我在浏览器中查看结果,我会得到以下结果:

[{"position":"","lastName":"","phone":"+39 06 6118286","type":"technical","city":"","country":"","isPrimaryContact":true,"postalCode":"","address":"","email":"m.skofic@cgiar.org","description":"","province":"","firstName":"Milko Skofic","salutation":"","key":"48"},{"position":"","lastName":"","phone":"39-06-6118204","type":"administrative","city":"","country":"","isPrimaryContact":true,"postalCode":"","address":"IPGRI, Via Tre Denari, 472/a, 00057, Maccarese, Rome, Italy,","email":"eurisco@cgiar.org","description":"","province":"","firstName":"Ms. Sonia Dias","salutation":"","key":"49"}]
4

3 回答 3

1

查看getJSONjQuery 文档中的方法。

辛税:

$.getJSON(url, data, function success);

所以,你可以尝试这样的事情:

$.getJSON("http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts", null, function(data) {


      // loop in your result if it is an array
      $.each(data, function(i, item) {

         // use data[i].property to access each property of your array.
         // for sample:

         var p = data[i].position;
         var l = data[i].lastName;

      });​

   });
于 2013-02-07T15:32:31.080 回答
0

如果您从不同的架构/主机/端口组合(例如https://gbrds.gbif.com:8080)请求 URL,您的浏览器将由于违反同源策略而引发安全异常

解决此问题的一种方法是,如果您可以实现jquery 也支持的jsonp 。

于 2013-02-07T15:33:25.200 回答
0

您需要使用 JSONP,因为它不在同一个域中。

$.getJSON("http://gbrds.gbif.org/registry/organisation/a3c228d0-3110-11db-abb8-b8a03c50a862.json?op=contacts&callback=?", function(data) {
    console.log(data);
});
于 2013-02-07T15:36:30.827 回答