我的目标是创建一个OData查询,该查询仅获取"Value": 100000000,
数据以用于Options数组中的最后一个条目。我只需要在响应数据中发送最后一个Option的Value
字段,然后Java接收响应并进行一些处理。我不允许将整个响应发送到Java。
我正在尝试解析Global Option Sets中的数据。我在解析Options ComplexType时遇到问题,到目前为止,在我当前的查询中只能到达选项级别。
https://myorg.api.crm.dynamics.com/api/data/v9.0/GlobalOptionSetDefinitions(06d1a507-4d57-e911-a82a-000d3a1d5203)/Microsoft.Dynamics.CRM.OptionSetMetadata
当前示例响应如下。由于Options是ComplexType,因此我没有找到任何文档或指南可以为我提供正确的方法指导。如果可以按照我希望的方式来运行此OData查询,则最终可以用Java实现我的方案。
{
"@odata.context": "https://myorg.api.crm.dynamics.com/api/data/v9.0/$metadata#GlobalOptionSetDefinitions/Microsoft.Dynamics.CRM.OptionSetMetadata/$entity",
"ParentOptionSetName": null,
"IsCustomOptionSet": true,
"IsGlobal": true,
"IsManaged": false,
"Name": "new_customoptionset",
"ExternalTypeName": "",
"OptionSetType": "Picklist",
"IntroducedVersion": "1.0",
"MetadataId": "06d1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null,
"Options": [
{
"Value": 100000000,
"Color": "#0000ff",
"IsManaged": false,
"ExternalValue": "",
"ParentValues": [],
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [
{
"Label": "a",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "09d1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "a",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "09d1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [
{
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0bd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0bd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
}
},
{
"Value": 100000001,
"Color": "#0000ff",
"IsManaged": false,
"ExternalValue": "",
"ParentValues": [],
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [
{
"Label": "b",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0cd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "b",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0cd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [
{
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0ed1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0ed1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
}
},
{
"Value": 100000002,
"Color": "#0000ff",
"IsManaged": false,
"ExternalValue": "",
"ParentValues": [],
"MetadataId": null,
"HasChanged": null,
"Label": {
"LocalizedLabels": [
{
"Label": "c",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0fd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "c",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "0fd1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
},
"Description": {
"LocalizedLabels": [
{
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "11d1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "11d1a507-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
}
}
],
"Description": {
"LocalizedLabels": [
{
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "83ca9f0d-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "83ca9f0d-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
},
"DisplayName": {
"LocalizedLabels": [
{
"Label": "MyCustom Option Set",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "82ca9f0d-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
],
"UserLocalizedLabel": {
"Label": "MyCustom Option Set",
"LanguageCode": 1033,
"IsManaged": false,
"MetadataId": "82ca9f0d-4d57-e911-a82a-000d3a1d5203",
"HasChanged": null
}
},
"IsCustomizable": {
"Value": true,
"CanBeChanged": true,
"ManagedPropertyLogicalName": "iscustomizable"
}
}
我能够用Java过滤JSON,但是我还是想先过滤OData以获得单个Value
字段。
try {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://myorg.api.crm.dynamics.com/api/data/v9.0/GlobalOptionSetDefinitions%28" +
optionSetGuidString +
"%29/Microsoft.Dynamics.CRM.OptionSetMetadata/Options")
.get()
.addHeader("Authorization", "Bearer " + accessToken)
.build();
Response response = client.newCall(request).execute();
String dataReturnedFromGetOptions = response.body().string();
JSONObject json = new JSONObject(dataReturnedFromGetOptions);
JSONArray jsonArray = (JSONArray) json.get("value");
JSONObject jsonObject = (JSONObject) jsonArray.get(jsonArray.length() - 1);
previousValue = jsonObject.getInt("Value");
}
catch (IOException e) { }