来自Google电子表格的JSON数据 [英] JSON data from google spreadsheet

查看:230
本文介绍了来自Google电子表格的JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经历了这个小提琴,其中有一个具有json数据的三个下拉菜单的示例。我在Google 此处的电子表格中提供了示例。现在可以将此电子表格数据呈现在jiddle格式的小提琴中给出的示例。我知道我们可以将电子表格转换为json,

I went through this fiddle which have a sample of three dropdown with json data. I have a sample google spreadsheet here. Now is it possible to render this spreadsheet data to the example given at fiddle as json format. I know we can convert the spreadsheet to json as,

 var query = new google.visualization.Query('http://spreadsheets.google.com/tq?key=0AozvCNI02VmpdDkwR3RETmczbTI4ZFJhTXJkZHlUbEE#gid=0');
 query.send(handleQueryResponse);
 }
 function handleQueryResponse(response) {
    data = response.getDataTable();
    }

但使用此下拉菜单不起作用。

But using this the dropdown didn't works.

推荐答案

我不知道你在做什么,但可以通过不同的方式完成。请使用您的示例数据查看此小提琴,并在下面查看代码。

I'm not sure about the way you're doing it but it can be accomplished a different way. Please see this fiddle using your example data, and below for the code.

基本上,您使用以下HTML脚本标签从电子表格中调用JSON数据。

Basically you call the JSON data from your spreadsheet with the below HTML script tags.

<script src="http://spreadsheets.google.com/feeds/list/0An1-zUNFyMVLdEFEdVV3N2h1SUJOdTdKQXBfbGpNTGc/1/public/values?alt=json-in-script&amp;callback=importGSS"></script>

请注意,我链接到您的副本电子表格,因为它需要通过发布

Please note I'm linking to a copy of your spreadsheet as it requires it to by published

然后你可以使用下面的脚本处理数据。

Then the you can handle the data with the below script.

function importGSS(json){
    for(var i = 0; i < json.feed.entry.length; i++){
        var entry = json.feed.entry[i];
        $('#departments').append('<option>' + entry.gsx$subdivision.$t + '</option>');
        $('#subject').append('<option>' + entry.gsx$section.$t + '</option>');
        $('#services').append('<option>' + entry.gsx$station.$t + '</option>');
    }
}

您可以明显地适应自己的需求。

You can obviously adapt to your own needs.

这篇关于来自Google电子表格的JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆