在 Azure 逻辑应用程序中筛选数组
Filter an array in Azure Logic Apps
这看起来应该是直截了当的,但事实并非如此,这表明我还没有理解某些东西。
我有一个简单的数组变量,其内容如下。我想对其进行过滤,以便我只看到政策为 X 的项目,以便我可以获得文档元素的值。
我试过:
filter @variables('myArray') where @equals('policy','X')
@contains('policy','X')
filter @variables('myArray') where @contains(@variables('myArray'),'X'
在每种情况下,数组都进入过滤器数组操作并完全留空。非常感谢收到任何帮助。
[
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
}
]
您可以在过滤数组之前使用Parse JSON
。考虑到您提供的示例,我们已经在我们的逻辑应用程序中对其进行了测试,并且可以正常工作。这是我的逻辑应用程序的屏幕截图供您参考:
结果:
考虑数组的另一个样本
[
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
},
{
"document": "D",
"min": 7500002,
"policy": "X"
}
]
结果:
下面是我的逻辑应用程序的代码视图
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Filter_array_2": {
"inputs": {
"from": "@body('Parse_JSON')",
"where": "@equals(item()['policy'], 'X')"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Query"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "SampleArray1",
"type": "array",
"value": [
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
}
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@variables('SampleArray1')",
"schema": {
"items": {
"properties": {
"document": {
"type": "string"
},
"min": {
"type": "integer"
},
"policy": {
"type": "string"
}
},
"required": [
"document",
"min",
"policy"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
这看起来应该是直截了当的,但事实并非如此,这表明我还没有理解某些东西。
我有一个简单的数组变量,其内容如下。我想对其进行过滤,以便我只看到政策为 X 的项目,以便我可以获得文档元素的值。
我试过:
filter @variables('myArray') where @equals('policy','X')
@contains('policy','X')
filter @variables('myArray') where @contains(@variables('myArray'),'X'
在每种情况下,数组都进入过滤器数组操作并完全留空。非常感谢收到任何帮助。
[
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
}
]
您可以在过滤数组之前使用Parse JSON
。考虑到您提供的示例,我们已经在我们的逻辑应用程序中对其进行了测试,并且可以正常工作。这是我的逻辑应用程序的屏幕截图供您参考:
结果:
考虑数组的另一个样本
[
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
},
{
"document": "D",
"min": 7500002,
"policy": "X"
}
]
结果:
下面是我的逻辑应用程序的代码视图
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Filter_array_2": {
"inputs": {
"from": "@body('Parse_JSON')",
"where": "@equals(item()['policy'], 'X')"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Query"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "SampleArray1",
"type": "array",
"value": [
{
"document": "A",
"min": 7500001,
"policy": "X"
},
{
"document": "B",
"min": 7500001,
"policy": "Y"
},
{
"document": "C",
"min": 7500001,
"policy": "Z"
}
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Parse_JSON": {
"inputs": {
"content": "@variables('SampleArray1')",
"schema": {
"items": {
"properties": {
"document": {
"type": "string"
},
"min": {
"type": "integer"
},
"policy": {
"type": "string"
}
},
"required": [
"document",
"min",
"policy"
],
"type": "object"
},
"type": "array"
}
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}