从谷歌应用脚​​本中的Javascript对象中提取字段

时间:2012-11-16 19:34:11

标签: json google-apps-script

我是新手,答案很简单,但请帮助。

我从查询中返回以下内容,这是结果的jsonParse

{"totalSize":1,
"done":true,
"records":
    [{"attributes": 
    {
        "type":"Account",
        "url":"/services/data/v21.0/sobjects/Account/001C0000012Z8Y5IAK"
    },
    "Id":"001C0000012Z8Y5IAK"
    }] 
}

如何在Id时将totalSize = 1最后提取到变量中?

1 个答案:

答案 0 :(得分:1)

objectName.records [0] .Id会做的伎俩。适当增加记录索引。

样本 -

var sforceResponse = {"totalSize":1,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v21.0/sobjects/Account/001C0000012Z8Y5IAK"},"Id":"001C0000012Z8Y5IAK"}]}

sforceResponse.records[0].Id //this variable contains the Id.