【问题标题】:Google calendar returns not a valid json fileGoogle 日历返回无效的 json 文件
【发布时间】:2014-09-11 18:57:42
【问题描述】:

我们正在使用 AngularJS 制作一个网站。我们需要谷歌日历活动。 我尝试从谷歌日历加载数据。

在这里你可以找到json文件:http://www.google.com/calendar/feeds/nmk97b3l07ncb9f9h5ap5ffo2c@group.calendar.google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true

但 Angulair 并不能将其识别为 json 文件。

有没有办法将它作为 json 文件获取?

【问题讨论】:

  • 它是 JSON。它只是封装在一个回调中。
  • 根据 RFC 4627(JSON 规范),JSON 输入无效。意外的令牌 // API 回调...使用 json 验证器。
  • 为什么不使用 Moment.js 之类的库将数据转换为标准数据?

标签: javascript json angularjs calendar


【解决方案1】:

insertAgenda 是 jsonp-callback-parameter。

试试这个:

var url = 'http://www.google.com/calendar/feeds/nmk97b3l07ncb9f9h5ap5ffo2c@group.calendar.google.com/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true';

$.ajax({
   type: 'GET',
    url: url,
    async: false,
    jsonpCallback: 'insertAgenda', //The callback parameter in Google Calendar response
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(json) {
       console.dir(json);
    }
});

DEMO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2014-03-27
    • 2020-10-21
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    相关资源
    最近更新 更多