【问题标题】:JSON object extract from big query database using app script使用应用脚本从大查询数据库中提取 JSON 对象
【发布时间】:2015-04-02 17:23:48
【问题描述】:

我有一个大查询表,其中有一个 JSON 对象作为表中的字段之一。如何使用 app 脚本从 JSON 对象中提取数据。对象本身是嵌套的。看起来是这样的

{
    "uid": "124551",
    "subjects": [
        {
            "tid": 37,
            "title": "Algebra",
            "html_id": "algebra",
            "selected": true
        },
        {
            "tid": 214853,
            "title": "Trigonometry",
            "html_id": "trigonometry",
            "selected": true
        },
        {
            "tid": 38,
            "title": "Geometry",
            "html_id": "geometry",
            "selected": true
        }
    ],
    "cellphone": "09178854579",
    "educations": [
        {
            "index": 0,
            "schoolname": "University of the Philippines - Los Baños",
            "degree": "BS Mathematics",
            "major": "Mathematics",
            "eduFrom": "2009-05-31T16:00:00.000Z",
            "eduTo": "2013-04-26T16:00:00.000Z",
            "eduFromTs": 1243785600,
            "eduToTs": 1366992000
        }
    ],
    "info": {
        "os": "Windows",
        "internet": "ADSL",
        "browser": "Chrome",
        "network": "Wireless",
        "speed": "",
        "timezone": "Asia/Hong_Kong"
    }
}

我想从教育领域提取所有学校名称。有什么想法吗?

【问题讨论】:

    标签: json google-apps-script google-bigquery


    【解决方案1】:

    使用 JSON 对象与使用 XML 类似,只是解析或编码 JSON 对象要容易得多。

    一旦检索到此字符串,只需在字符串上调用 JSON.parse() 即可获取本机对象表示。

    var data = JSON.parse(json);
    Browser.msgBox(data.info.os);
    

    其他示例代码在https://developers.google.com/apps-script/advanced/bigquery#run_query

    【讨论】:

      猜你喜欢
      • 2019-09-16
      • 2020-06-02
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2010-11-13
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多