我正在编写一个脚本,通过脚本将来自twitter api的数据下载到Google表格中。
来自twitter的json文件有一条奇怪的路径,根据路径分析器获取名称,它是:[0] .trends [k] .name
在尝试解析数据时,似乎所有事情都与最后一步有所不同:Trending.getRange(1,1,1,1).setValue(response_json.[0].trends[0].name);
我会收到以下错误消息:之后缺少名称。运营商。 (第38行,文件"代码")
任何人都有任何想法我怎么解析这个?
JSON文件如下:
[
{
"trends": [
{
"name": "#MakeLifeBetterIn3Words",
"query": "%23MakeLifeBetterIn3Words",
"url": "http://twitter.com/search?q=%23MakeLifeBetterIn3Words",
"promoted_content": null
},
{
"name": "#ThingsJesusNeverSaid",
"query": "%23ThingsJesusNeverSaid",
"url": "http://twitter.com/search?q=%23ThingsJesusNeverSaid",
"promoted_content": null
},
{
"name": "#askjack",
"query": "%23askjack",
"url": "http://twitter.com/search?q=%23askjack",
"promoted_content": null
},
{
"name": "#charitytuesday",
"query": "%23charitytuesday",
"url": "http://twitter.com/search?q=%23charitytuesday",
"promoted_content": null
},
{
"name": "#TravelTuesday",
"query": "%23TravelTuesday",
"url": "http://twitter.com/search?q=%23TravelTuesday",
"promoted_content": null
},
{
"name": "Flight of the Conchords",
"query": "%22Flight+of+the+Conchords%22",
"url": "http://twitter.com/search?q=%22Flight+of+the+Conchords%22",
"promoted_content": null
},
{
"name": "Battle of Britain",
"query": "%22Battle+of+Britain%22",
"url": "http://twitter.com/search?q=%22Battle+of+Britain%22",
"promoted_content": null
},
{
"name": "Carol Kirkwood",
"query": "%22Carol+Kirkwood%22",
"url": "http://twitter.com/search?q=%22Carol+Kirkwood%22",
"promoted_content": null
},
{
"name": "Longannet",
"query": "Longannet",
"url": "http://twitter.com/search?q=Longannet",
"promoted_content": null
},
{
"name": "Chris Rogers",
"query": "%22Chris+Rogers%22",
"url": "http://twitter.com/search?q=%22Chris+Rogers%22",
"promoted_content": null
}
],
"as_of": "2015-08-18T11:16:11Z",
"created_at": "2015-08-18T11:11:13Z",
"locations": [
{
"name": "London",
"woeid": 44418
}
]
}
]
答案 0 :(得分:0)
问题在于:
response_json.[0].trends[0].name
// ^
将其替换为:
response_json[0].trends[0].name
请勿在括号前使用点.
。