[英]How to parse JSON response in Google App Script?
I'm using a Google AdWords/App Script and I got this response from DoubleClick Search.我使用的是 Google AdWords/App 脚本,我从 DoubleClick Search 得到了这个响应。 I'm trying to parse it to put in a Sheet/ into an array to work with and I'm not having much luck.
我正在尝试解析它以将它放入一个 Sheet/ 到一个数组中以进行处理,但我运气不佳。 Thank you for taking a look.
感谢您的浏览。
This is the original code:这是原始代码:
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"
}
]
}
It is similar to regular JavaScript.它类似于常规的 JavaScript。 You get the JSON response with UrlFetchApp service and then access the properties using the dot notation.
您使用 UrlFetchApp 服务获取 JSON 响应,然后使用点表示法访问属性。
var response = authUrlFetch.fetch(url, options);
var data = JSON.parse(response.getContentText());
Logger.log(data.request.reportType);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.