Google Script解析JSON -下面的路径是什么?

Google Script parsing JSON - what would be the path for the following?

本文关键字:路径 是什么 -下 Script 解析 JSON Google      更新时间:2023-09-26

我正在编写一个脚本,其中将通过脚本从twitter api下载数据到Google Sheets。

来自twitter的json文件有一个奇怪的路径,根据路径分析器,获取名称,它是:[0].trends[k].name

一切似乎都在工作,除了最后一步,当它试图解析数据:Trending.getRange(1,1,1,1).setValue(response_json.[0].trends[0].name);

和我将得到以下错误消息:之后缺少名称。操作符。(第38行,文件"Code")

有人知道我该如何解析这个吗?

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
            }
        ]
    }
]

问题在这里:

response_json.[0].trends[0].name
//           ^

替换为:

response_json[0].trends[0].name

不要在括号前使用点.