我正在尝试构建一个仅提取特定数据的GET请求,但我在使用OData时遇到了问题。 从API中提取的对象如下所示:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"ConceptId": 1,
"CreatedDateTime": "2015-10-20T18:36:46.353",
"ModifiedDateTime": "2018-01-26T14:35:33.447",
"DeletedDateTime": null,
"DoingBusinessAs": "Appliance.inc",
"Status": "Active",
"IsOwned": true,
"FranchiseeName": "Appliance Inc - Ann Arbor, MI - MLY 1001",
"LicenseNumber": "ML89023",
"City": "Ann Arbor",
"StateAbbr": "MI",
"PostalCode": "48104",
"ContactFirstName": "Doug",
"ContactLastName": "Smith",
"Country": "United States"
}
},
我正在执行此GET请求以获取该数据:
#url#&$expand=Franchise&$select=FranchiseId, PostalCode
我正在使用& $ expand = Franchise,因为我需要" FranchiseeName"来自特许经营对象,但我不想拉出该对象的其余数据。 如何编写请求,因此我只提取三个字段:PostalCode,FranchiseId,FranchiseeName。该对象应如下所示:
{
"PostalCode": "48103",
"FranchiseId": 397,
"FranchiseeName": "Appliance.inc"
}
答案 0 :(得分:1)
我认为#url#
是您实体的OData URI的占位符,例如http://server/odata/entityName
。
以下网址应该可以获得您需要的数据:
http://server/odata/entityName?$select=PostalCode,FranchiseId&$expand=Franchise($select=FranchiseeName)
这应该只返回所需的数据,但仍然具有与完整数据相同的结构,例如:
{
"PostalCode": "48103",
"FranchiseId": 397,
"Franchise": {
"FranchiseeName": "Appliance.inc"
}
}