Google Docs Spreadsheet to JSON

半腔热情 提交于 2019-11-28 06:33:54

The src attribute in your script tag is an invalid link (and you can see this for yourself by viewing your link directly in a browser).

The feed/key/worksheet section of the URL has the right key but the wrong feed and worksheet.

In the URL, replace "feed" with either "cells" (separate value for each cell) or "list" (separate value for each row).

At the same time, replace "worksheet" with "od6" (indicating the leftmost, or default, sheet - see this blog post for accessing other sheets).

If you view this new URL directly in a browser, you can see that it returns a meaningful value.

Your final script tag might look like this:

<script src="https://spreadsheets.google.com/feeds/list/1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I/od6/public/values?alt=json-in-script&callback=importGSS"></script>

For more info, you can see an example on the Google Developers site

APISpark PaaS has a feature to create and deploy a custom JSON API based on a GSpreadsheet. That might help and give you more control on the web API (CORS support, authentication, custom domain and so on).

See the tutorial here: https://apispark.com/docs/tutorials/google-spreadsheet

You may consider use an alternative to this request of your sheet data, because this method is deprecated. Anyway, you can still using another feed format, you can see this alternatives in: https://spreadsheets.google.com/feeds/worksheets/your-spreadsheet-id/private/full

In that result you can see any export formats are availables. Can help you an CSV or alt JSON visualization format?

Another potential solution here is to use this https://gist.github.com/ronaldsmartin/47f5239ab1834c47088e to wrap around your existing spreadsheet.

Add the id and sheet html param to the URL below.

https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec

Eg: your id is your sheet id which is

1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I

and your sheet which is

Sheet1

In your case you can actually see your data (it's actually working) here as json at

https://script.google.com/macros/s/AKfycbzGvKKUIaqsMuCj7-A2YRhR-f7GZjl4kSxSN1YyLkS01_CfiyE/exec?id=1SKI5773_68HiSve1fsz7fr4gotjFWHB7KBuVsOlLz6I&sheet=Sheet1

To be safe, you should deploy the code sheetAsJson.gs in the github gist above as your own in your Google Drive.

You have plenty of possible answers above. For those that come anew, if you're looking for a more controlled JSON generator, check out this gist:

JSONPuller

It takes in a Spreadsheet and returns an array of objects, with the lined that you decide as the headers (defaults to whichever line is frozen)

Cheers,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!