我正在调用Salesforce API来基于动态查询提取数据,因此一个或多个字段以及可选的相关对象,在编译时都不知道。响应的结构如下:
{
"totalSize" : 2,
"done" : true,
"records" : [ {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v36.0/sobjects/Contact/0034J000005TO7AQAW"
},
"Id" : "0034J000005TO7AQAW",
"Name" : "Arthur Song",
"Account" : {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v36.0/sobjects/Account/0014J000005WC3WQAW"
},
"Name" : "United Oil & Gas Corp.",
"Type" : "Customer - Direct",
"Owner" : {
"attributes" : {
"type" : "User",
"url" : "/services/data/v36.0/sobjects/User/0054J000001Wz4xQAC"
},
"Name" : "Bob Jones",
"LastModifiedDate" : "2019-07-12T10:50:39.000+0000"
}
}
}, {
"attributes" : {
"type" : "Contact",
"url" : "/services/data/v36.0/sobjects/Contact/0034J000005TO7BQAW"
},
"Id" : "0034J000005TO7BQAW",
"Name" : "Ashley James",
"Account" : {
"attributes" : {
"type" : "Account",
"url" : "/services/data/v36.0/sobjects/Account/0014J000005WC3ZQAW"
},
"Name" : "United Oil & Gas, UK",
"Type" : "Customer - Direct",
"Owner" : {
"attributes" : {
"type" : "User",
"url" : "/services/data/v36.0/sobjects/User/0054J000001Wz4xQAC"
},
"Name" : "Bob Jones",
"LastModifiedDate" : "2019-07-12T10:50:39.000+0000"
}
}
} ]
}
对于不熟悉Salesforce数据结构的任何人,这将显示2个联系人(ID,名称),以及每个联系人(名称,类型)和帐户所有者(名称,LastModifiedDate)的相关帐户。我想将其扁平化为一个数据结构,我可以对其进行迭代以生成例如CSV,或在屏幕上显示结果。该结构每个联系人应具有1条记录,具体如下:
Id |姓名|帐户名|帐户类型| AccountOwnerName | AccountOwnerLastModifiedDate
问题在于,由于我不知道在编译时属性将是什么,所以我不能(我不认为)强烈地键入绑定,而且我也不知道如何遍历属性。谁能指出我正确的方向?谢谢。