简体   繁体   English

getJson解析器不起作用

[英]getJson parser doesn't work

Hi I am trying to parser the json response of the url but i am not able to do it. 嗨,我正在尝试解析url的json响应,但我无法做到。

$(document).ready(function() {
    $.getJSON('https://www.googleapis.com/oauth2/v1/userinfo?&access_token=xxxxxxxxxxxxx&token_type=Bearer&expires_in=3600', function(data) {
        alert (c.email);
    });
});

In this page there is my code http://pastie.org/3379735 在此页面中有我的代码http://pastie.org/3379735

I hope you can help me. 我希望你能帮助我。

What is c.email, think you want data.email 什么是c.email,认为您需要data.email

$(document).ready(function() {

  $.getJSON('https://www.googleapis.com/oauth2/v1/userinfo?&access_token=xxxxxxxxxxxxx&token_type=Bearer&expires_in=3600&callback=?', function(data) {

    alert (data.email);

  });
});

Update 更新资料

as the OP has now stated after reading the documentation you need to provied the callback for jsonp as part of the path, not the params in the form of 正如OP现在在阅读文档后所说的那样,您需要提供jsonp的回调作为路径的一部分,而不是形式为params的params。

https://oauth2-login-demo.appspot.com/oauthcallback?code={authorizationCode}

docs can be found here 可以在这里找到文档

Due to the same origin policy restriction you cannot send cross domain AJAX requests. 由于相同的原始策略限制,您无法发送跨域AJAX请求。 There's no JSONP support for this so you cannot directly access his url from your code. 没有JSONP支持,因此您无法直接从代码中访问他的url。

You may take a look at the following demo based on the gwt-oauth2.js script which uses this code to authenticate with Google. 您可以基于gwt-oauth2.js脚本查看以下演示 ,该脚本使用此代码向Google进行身份验证。

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

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