App脚本中的JSON响应

App脚本中的JSON响应

本文介绍了如何解析Google App脚本中的JSON响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Google AdWords /应用脚本,我从DoubleClick Search获得了此回复。我试图解析它以将Sheet /放入数组中以使用,而且我没有太多运气。谢谢你看看。

I'm using a Google AdWords/App Script and I got this response from 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. 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"
  }
 ]
}


推荐答案

与常规JavaScript类似。您可以使用UrlFetchApp服务获取JSON响应,然后使用点符号访问属性。

It is similar to regular JavaScript. You get the JSON response with UrlFetchApp service and then access the properties using the dot notation.

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

这篇关于如何解析Google App脚本中的JSON响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 17:08