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

时间:2022-08-22 11:29:26

I am very new at this and the answer is probably very simple, but please help.

我对这方面很陌生,答案可能很简单,但请帮忙。

I get the following returned from a query, this is a jsonParse of the result

我从查询中得到以下结果,这是结果的jsonParse

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

How do I extract the Id at the end into a variable when totalSize = 1?

当totalSize = 1时,如何将最终的Id提取到变量中?

1 个解决方案

#1


1  

objectName.records[0].Id will do the trick. Increment records index appropriately.

objectName.records[0]。我来搞定。适当增加记录索引。

Sample -

样品-

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. 

#1


1  

objectName.records[0].Id will do the trick. Increment records index appropriately.

objectName.records[0]。我来搞定。适当增加记录索引。

Sample -

样品-

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.