以JSON格式获取Google Spradsheet数据

时间:2016-01-30 10:05:48

标签: json http google-sheets

我正在尝试使用JSON获取Google电子表格内容,但ID似乎无法使用以下方式工作。 我正在使用以下URL发送HTTP请求。您只需将其复制到URL即可查看结果。

https://spreadsheets.google.com/feeds/list/1Sp18_fOs8SSP_fwB54lv7IoL42uDaioZM1LTRD4rL8o/od6/public/values?alt=json

1 个答案:

答案 0 :(得分:0)

这很好用:

<!DOCTYPE>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<head>
</head>
<body>
<ul id="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact</a></li>
</ul>
<div class="results"></div> 
<script type="text/javascript">


 // ID of the Google Spreadsheet
 var spreadsheetID = "1Sp18_fOs8SSP_fwB54lv7IoL42uDaioZM1LTRD4rL8o";

 // 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";

 $.getJSON(url, function(data) {

  var entry = data.feed.entry;


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

 });

</script>
</body>
</html>