Javascript 有没有办法将字段作为JSON对象而不是从Google电子表格中获取字符串?

Javascript 有没有办法将字段作为JSON对象而不是从Google电子表格中获取字符串?,javascript,json,url,google-sheets,google-spreadsheet-api,Javascript,Json,Url,Google Sheets,Google Spreadsheet Api,通过使用类似url的https://spreadsheets.google.com/feeds/list/mysheetid/od6/public/basic?alt=json 我得到的字段数据是以数组的形式输入的,在每个字段中,内容都是以普通字符串的形式获取的,这可能会给解析带来问题。例如,当一个字段的内容变得像内容时:abc在这里,冒号是分隔符。在很多情况下都可以。但是我尝试过,当我改变字段值时,它包含的值不仅仅是abc,而是ab content:c,那么它很容易混淆,好吧,不需要编写太多解

通过使用类似url的https://spreadsheets.google.com/feeds/list/mysheetid/od6/public/basic?alt=json

我得到的字段数据是以数组的形式输入的,在每个字段中,内容都是以普通字符串的形式获取的,这可能会给解析带来问题。例如,当一个字段的内容变得像内容时:abc在这里,冒号是分隔符。在很多情况下都可以。但是我尝试过,当我改变字段值时,它包含的值不仅仅是abc,而是ab content:c,那么它很容易混淆,好吧,不需要编写太多解析代码

我想知道是否需要编写这种解析器才能将字段中的所有值作为实际对象,还是我自己编写?我知道怎么做,但如果谷歌电子表格已经提供了我不知道的功能,我不想重新发明轮子

例如:

{ 编码:UTF-8, 提要:{ 作者:[ { 电邮:{ $t:adamchenwei@gmail.com }, 姓名:{ $t:adamchenwei } } ], 类别:[ { 方案:http://schemas.google.com/spreadsheets/2006, 术语:http://schemas.google.com/spreadsheets/2006list } ], 条目:[ { 类别:[ { 方案:http://schemas.google.com/spreadsheets/2006, 术语:http://schemas.google.com/spreadsheets/2006list } ], 内容:{ $t:_cokwr:some value:afield:, 类型:文本 }, 身份证:{ $t:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cokwr }, 链接:[ { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cokwr, 雷尔:赛尔夫, 类型:application/atom+xml } ], 标题:{ $t:外地, 类型:文本 }, 更新:{ $t:2017-01-15T15:05:08.549Z } }, { 类别:[ { 方案:http://schemas.google.com/spreadsheets/2006, 术语:http://schemas.google.com/spreadsheets/2006list } ], 内容:{ $t:_cokwr:antourh值, 类型:文本 }, 身份证:{ $t:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cpzh4 }, 链接:[ { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cpzh4, 雷尔:赛尔夫, 类型:application/atom+xml } ], 标题:{ $t:Antourh, 类型:文本 }, 更新:{ $t:2017-01-15T15:05:08.549Z } }, { 类别:[ { 方案:http://schemas.google.com/spreadsheets/2006, 术语:http://schemas.google.com/spreadsheets/2006list } ], 内容:{ $t:_cokwr:3岁左右, 类型:文本 }, 身份证:{ $t:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cre1l }, 链接:[ { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cre1l, 雷尔:赛尔夫, 类型:application/atom+xml } ], 标题:{ $t:3, 类型:文本 }, 更新:{ $t:2017-01-15T15:05:08.549Z } }, { 类别:[ { 方案:http://schemas.google.com/spreadsheets/2006, 术语:http://schemas.google.com/spreadsheets/2006list } ], 内容:{ $t:_cokwr:,heyNewField:, 类型:文本 }, 身份证:{ $t:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/chk2m }, 链接:[ { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/chk2m, 雷尔:赛尔夫, 类型:application/atom+xml } ], 标题:{ $t:heyNewField, 类型:文本 }, 更新:{ $t:2017-01-15T15:05:08.549Z } } ], 身份证:{ $t:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic }, 链接:[ { href:https://docs.google.com/spreadsheets/d/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/pubhtml, 雷尔:候补, 类型:application/atom+xml }, { href:https://spreadsheets.google.com/feeds/li st/1DvBoPjfiGNft4IcDwTKYNHYq\u FLDlU5\u 4oI7AOhPzaM/od6/public/basic, rel:http://schemas.google.com/g/2005feed, 类型:application/atom+xml }, { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic, rel:http://schemas.google.com/g/2005post, 类型:application/atom+xml }, { href:https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic?alt=json, 雷尔:赛尔夫, 类型:application/atom+xml } ], openSearch$startIndex:{ $t:1 }, openSearch$totalResults:{ $t:4 }, 标题:{ $t:1张, 类型:文本 }, 更新:{ $t:2017-01-15T15:05:08.549Z }, xmlns:http://www.w3.org/2005/Atom, xmlns$gsx:http://schemas.google.com/spreadsheets/2006/extended, xmlns$openSearch:http://a9.com/-/spec/opensearchrss/1.0/ }, 版本:1.0
} 没有JSON对象这样的东西。在JSON中有对象和表示这些对象的字符串。获取一个字符串,并使用obj=JSON.parsestr将其解析为一个对象。单元格的内容埋在该对象的几层深处,可以通过

var content = obj.feed.entry[0].content.$t
或另一个索引代替0。不要担心包含冒号之类的内容,它们由引号正确地分隔,并且将被正确地解析出来。当然,您不应该编写自己的JSON解析器;JavaScript中有一个

此外,您还可以在带有回调的脚本中使用json:将basic?alt=json替换为

在请求URL的末尾。这里yourFunction是JS文件中执行请求的函数的名称。调用此函数时,参数将是已从该JSON字符串解析的对象。这种方法除了节省一个解析步骤外,还避免了CORS问题


脚本中的?alt=json和?alt=json都是遗留API,但显然它们仍然可以工作

什么是实际的json对象?有一些物体。还有使用JSON符号表示对象的字符串。后者使用JSON.parse转换为前者。@zaq I附带了一个data@zaq如您所见,它的字符串为:。有没有方法可以查询它们,比如它的sql是否只获取那些需要的json对象?而不是字符串,然后必须再次解析?
basic?alt=json-in-script&callback=yourFunction