【发布时间】:2017-05-30 11:12:55
【问题描述】:
通过使用像https://spreadsheets.google.com/feeds/list/mysheetid/od6/public/basic?alt=json这样的网址
我得到的字段数据位于entry 下作为数组,并且在每个数组中,内容都是以纯字符串形式获取的,解析时可能会出现问题。例如,当字段的内容变为content: abc is here 并且冒号是分隔符时。在很多情况下都可以。但是我尝试更改包含不仅是 abc 而是 ab content: c 的值的字段值,那么它很容易混淆,好吧,无需编写太多解析代码。
我想知道是否需要编写这种解析器才能将字段中的所有值作为实际对象,还是我只需要自己编写? (我知道怎么做,但如果 Google 电子表格已经提供了这样一个我不知道的功能,我不想重新发明轮子)。
例子:
{
"encoding": "UTF-8",
"feed": {
"author": [
{
"email": {
"$t": "adamchenwei@gmail.com"
},
"name": {
"$t": "adamchenwei"
}
}
],
"category": [
{
"scheme": "http://schemas.google.com/spreadsheets/2006",
"term": "http://schemas.google.com/spreadsheets/2006#list"
}
],
"entry": [
{
"category": [
{
"scheme": "http://schemas.google.com/spreadsheets/2006",
"term": "http://schemas.google.com/spreadsheets/2006#list"
}
],
"content": {
"$t": "_cokwr: some value: afield:",
"type": "text"
},
"id": {
"$t": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cokwr"
},
"link": [
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cokwr",
"rel": "self",
"type": "application/atom+xml"
}
],
"title": {
"$t": "afield",
"type": "text"
},
"updated": {
"$t": "2017-01-15T15:05:08.549Z"
}
},
{
"category": [
{
"scheme": "http://schemas.google.com/spreadsheets/2006",
"term": "http://schemas.google.com/spreadsheets/2006#list"
}
],
"content": {
"$t": "_cokwr: antoerh value",
"type": "text"
},
"id": {
"$t": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cpzh4"
},
"link": [
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cpzh4",
"rel": "self",
"type": "application/atom+xml"
}
],
"title": {
"$t": "antoerh",
"type": "text"
},
"updated": {
"$t": "2017-01-15T15:05:08.549Z"
}
},
{
"category": [
{
"scheme": "http://schemas.google.com/spreadsheets/2006",
"term": "http://schemas.google.com/spreadsheets/2006#list"
}
],
"content": {
"$t": "_cokwr: 3rd something",
"type": "text"
},
"id": {
"$t": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cre1l"
},
"link": [
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/cre1l",
"rel": "self",
"type": "application/atom+xml"
}
],
"title": {
"$t": " 3rd",
"type": "text"
},
"updated": {
"$t": "2017-01-15T15:05:08.549Z"
}
},
{
"category": [
{
"scheme": "http://schemas.google.com/spreadsheets/2006",
"term": "http://schemas.google.com/spreadsheets/2006#list"
}
],
"content": {
"$t": "_cokwr: ,heyNewField:",
"type": "text"
},
"id": {
"$t": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/chk2m"
},
"link": [
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic/chk2m",
"rel": "self",
"type": "application/atom+xml"
}
],
"title": {
"$t": "heyNewField",
"type": "text"
},
"updated": {
"$t": "2017-01-15T15:05:08.549Z"
}
}
],
"id": {
"$t": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic"
},
"link": [
{
"href": "https://docs.google.com/spreadsheets/d/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/pubhtml",
"rel": "alternate",
"type": "application/atom+xml"
},
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic",
"rel": "http://schemas.google.com/g/2005#feed",
"type": "application/atom+xml"
},
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic",
"rel": "http://schemas.google.com/g/2005#post",
"type": "application/atom+xml"
},
{
"href": "https://spreadsheets.google.com/feeds/list/1DvBoPjfiGNft4IcDwTKYNHYq_FLDlU5_4oI7AOhPzaM/od6/public/basic?alt=json",
"rel": "self",
"type": "application/atom+xml"
}
],
"openSearch$startIndex": {
"$t": "1"
},
"openSearch$totalResults": {
"$t": "4"
},
"title": {
"$t": "Sheet1",
"type": "text"
},
"updated": {
"$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/"
},
"version": "1.0"
}
【问题讨论】:
-
什么是“实际的 json 对象”?有物体。并且有使用称为 JSON 的表示法的对象的字符串表示。后者使用
JSON.parse转换为前者。 -
@zaq 我附上了一个数据示例
-
@zaq 你可以看到它是带有
:的字符串。有没有办法可以查询它们,比如它的 sql 是否只获取需要的那些作为 json 对象?而不是字符串然后必须再次解析?
标签: javascript json url google-sheets google-spreadsheet-api