gpt4 book ai didi

javascript - 如何解析 Google App Script 中的 JSON 响应?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:28 25 4
gpt4 key购买 nike

我使用的是 Google AdWords/App 脚本,我从 DoubleClick Search 收到了此响应。我正在尝试解析它以将其放入 Sheet/数组中进行处理,但我运气不佳。谢谢你看一看。

这是原始代码:

var response = authUrlFetch.fetch(url, options);
var data = JSON.stringify(response.getContentText());
var parsedData = JSON.parse(data);

{
"kind": "doubleclicksearch#report",
"request": {
"reportType": "advertiser",
"columns": [
{
"columnName": "agency"
},
{
"columnName": "agencyId"
},
{
"columnName": "advertiser"
},
{
"columnName": "advertiserId"
}
],
"includeRemovedEntities": false,
"statisticsCurrency": "usd",
"startRow": 0,
"rowCount": 10000
},
"statisticsCurrencyCode": "USD",
"rowCount": 2,
"rows": [
{
"agency": "a",
"agencyId": "11111111111111",
"advertiser": "aa",
"advertiserId": "11111111111111"
},
{
"agency": "b",
"agencyId": "222222222222222",
"advertiser": "bb",
"advertiserId": "22222222222"
}
]
}

最佳答案

它类似于常规的 JavaScript。您使用 UrlFetchApp 服务获取 JSON 响应,然后使用点表示法访问属性。

var response = authUrlFetch.fetch(url, options);
var data = JSON.parse(response.getContentText());
Logger.log(data.request.reportType);

关于javascript - 如何解析 Google App Script 中的 JSON 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40552779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com