使用app脚本从大查询数据库中提取JSON对象

时间:2015-04-02 17:23:48

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

我有一个大的查询表,它有一个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"
    }
}

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

1 个答案:

答案 0 :(得分:0)

使用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