【问题标题】:Get data from Google sheet using json使用 json 从 Google 工作表中获取数据
【发布时间】:2016-05-24 09:16:18
【问题描述】:

我创建了一个 Google 表格,其中放置了很多逻辑和功能。现在我只想将工作表中的数据导入我的网站(在我的 html 项目中使用 MVC)。

我在这个网站上读到了它: https://ctrlq.org/code/20004-google-spreadsheets-json

这一切看起来都很简单,只要使用他的代码就可以正常工作,但也许我遗漏了一些东西。下面是我的代码,只添加了 $(document).ready 部分和我的电子表格 ID。

<div class="results"></div> 

<script>

 // ID of the Google Spreadsheet
 var spreadsheetID = "1-JfSulb2FIh0C-hyy-ihYV0ieFi3ephC75oYB1mrKr8";

 // Make sure it is public or set to Anyone with link can view 
 var url = "https://spreadsheets.google.com/feeds/list/" + spreadsheetID + "/od6/public/values?alt=json";
     $(document).ready(function () {
         $.getJSON(url, function(data) {

             var entry = data.feed.entry;

             $(entry).each(function(){
                  // Column names are name, age, etc.
                  $('.results').prepend('<h2>'+this.gsx$name.$t+'</h2><p>'+this.gsx$age.$t+'</p>');
             });
         });
  });

</script>

所以问题是我没有从工作表中获取任何数据到我的 html div 中。但是我尝试它只是空的。我还需要做些什么才能让它工作吗?我已将第一行中的单元格命名为命名和年龄,但什么也没得到。

我的 Google 表格:

https://docs.google.com/spreadsheets/d/1-JfSulb2FIh0C-hyy-ihYV0ieFi3ephC75oYB1mrKr8/edit?usp=sharing

除了将其公开并将代码复制到我的项目中之外,我还需要在工作表中做些什么吗?我想这是一个菜鸟问题,但我无法让它发挥作用。任何帮助将不胜感激!

【问题讨论】:

    标签: html json google-sheets


    【解决方案1】:

    代码没有错误。

    我出于某种原因删除了 _Layout 页面中的 jQuery 部分

    <script src="~/lib/jquery/dist/jquery.js"></script>
    

    我没想过要寻找的愚蠢错误。无论如何,现在它工作得很好:)

    【讨论】:

    • 我很想看看您的网站中的结果是什么样的,因为我正在尝试做类似的事情,这可能吗?
    • 很遗憾,该网站不再可用。但是一旦我开始使用它,它就很容易使用,你可以用任何你喜欢的方式来展示它。
    猜你喜欢
    • 1970-01-01
    • 2020-08-24
    • 2016-12-04
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多