如果您只想要一个只读数据库,这可以很容易地完成。您必须将 Google 表格发布到网络上并从其 url 中复制其 id。
例如我的工作表有这个网址:https://docs.google.com/spreadsheets/d/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/edit https://docs.google.com/spreadsheets/d/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/edit
中间的长字母数字字符串是我的工作表 ID。复制它并将其代替 XXXX 放在以下 url 中,如下所示:
https://spreadsheets.google.com/feeds/list/XXXX/1/public/basic?alt=json https://spreadsheets.google.com/feeds/list/XXXX/1/public/basic?alt=json"
所以最终的 url 看起来像这样:https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json
然后你可以简单地访问这个 url 并获取所有 json 数据。
使用 jQuery:
var $url = 'https://spreadsheets.google.com/feeds/list/1IHF0mSHs1HdYpIlIzYKG3O8SnAhKU_a6nEJSz04Togk/1/public/basic?alt=json';
$.getJSON($url,function(data){
alert(JSON.stringify(data.feed.entry));
});
你会得到一个很长的 json 结构。相关数据位于data.feed.entry中。在那里你会有很多条目。在每个属性上,您都会有一个“content”属性,并在其中包含一个“$t”属性。这些会给你所有的细胞。
因此,要获取第一行,您必须获取 data.feed.entry[0].content.$t。
希望能帮助到你。