【问题标题】:Parsing JSON using jquery not [duplicate]使用jquery解析JSON不是[重复]
【发布时间】:2013-12-06 22:53:26
【问题描述】:
var placesAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.8400,-117.2769&radius=500&types=museum&sensor=true&key=my_key_here";
$.getJSON(placesAPI, function (json) {
    var address = json.results[0].name;
    console.log('Name : ', name);
});

我正在尝试上面的代码,但没有成功。我确实输入了我的 API 密钥,并在网页上获得了 json 结果,但是当我尝试解析它们时,我收到一个错误“请求的资源上不存在'Access-Control-Allow-Origin'标头。来源'null'因此不允许访问。"

如何解析 JSON?

【问题讨论】:

标签: javascript jquery json


【解决方案1】:

试试下面的代码。我添加了 &callback=?根据说明到您的网址是以下post

var placesAPI = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=32.8400,-117.2769&radius=500&types=museum&sensor=true&key=my_key_here&callback=?";
$.getJSON(placesAPI, function (json) {
    var address = json.results[0].name;
    console.log('Name : ', name);
});

【讨论】:

    猜你喜欢
    • 2016-05-08
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多