【问题标题】:how to get a value of a json http response in azure logic app如何在 Azure 逻辑应用程序中获取 json http 响应的值
【发布时间】:2022-09-27 12:17:43
【问题描述】:

我试图通过解析下面的输出样本将“id”值设置为变量。 REST API 调用将返回多个值,如下所示,我感兴趣的是仅通过参数值或通过初始化一个变量。如何在 Azure 逻辑应用程序中进行此值提取?

非常感谢任何帮助。

[
  {
    \"id\": 1,
    \"name\": \"xyz-List\",
    \"data\": {
      \"urls\": [
        \"*.test1.com\",
        \"*.test2.com\"
      ],
      \"type\": \"exact\"
    },
    \"modify_by\": \"admin@xyz.com\",
    \"modify_time\": \"2022-06-29T21:05:27.000Z\",
    \"modify_type\": \"Created\",
    \"pending\": 0
  },
  {
    \"id\": 2,
    \"name\": \"abc-List\",
    \"data\": {
      \"urls\": [
        \"www.mytesting.com\"
      ],
      \"type\": \"exact\"
    },
    \"modify_by\": \"admin@xyz.com\",
    \"modify_time\": \"2022-06-29T21:05:27.000Z\",
    \"modify_type\": \"Created\",
    \"pending\": 0
  },
  {
    \"id\": 3,
    \"name\": \"azure-list\",
    \"data\": {
      \"type\": \"exact\",
      \"urls\": [
        \"www.xyz.com\",
        \"www.azure-test.com\"
      ],
      \"json_version\": 2
    },
    \"modify_by\": \"admin@xyz.com\",
    \"modify_time\": \"2022-09-26T01:25:20.000Z\",
    \"modify_type\": \"Edited\",
    \"pending\": 0
  }
]

标签: azure azure-logic-apps


【解决方案1】:

为了遍历 JSON,我使用了 for-each 循环并使用以下表达式提取了 Id 并将其值设置为变量。

@items('For_each')['id']

下面是我的逻辑应用程序的完整流程

结果:

要在您的逻辑应用程序中重现相同内容,您可以使用以下对我有用的代码视图。

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": [
                    {
                        "data": {
                            "type": "exact",
                            "urls": [
                                "*.test1.com",
                                "*.test2.com"
                            ]
                        },
                        "id": 1,
                        "modify_by": "admin@xyz.com",
                        "modify_time": "2022-06-29T21:05:27.000Z",
                        "modify_type": "Created",
                        "name": "xyz-List",
                        "pending": 0
                    },
                    {
                        "data": {
                            "type": "exact",
                            "urls": [
                                "www.mytesting.com"
                            ]
                        },
                        "id": 2,
                        "modify_by": "admin@xyz.com",
                        "modify_time": "2022-06-29T21:05:27.000Z",
                        "modify_type": "Created",
                        "name": "abc-List",
                        "pending": 0
                    },
                    {
                        "data": {
                            "json_version": 2,
                            "type": "exact",
                            "urls": [
                                "www.xyz.com",
                                "www.azure-test.com"
                            ]
                        },
                        "id": 3,
                        "modify_by": "admin@xyz.com",
                        "modify_time": "2022-09-26T01:25:20.000Z",
                        "modify_type": "Edited",
                        "name": "azure-list",
                        "pending": 0
                    }
                ],
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "For_each": {
                "actions": {
                    "Set_variable": {
                        "inputs": {
                            "name": "Id",
                            "value": "@items('For_each')['id']"
                        },
                        "runAfter": {},
                        "type": "SetVariable"
                    }
                },
                "foreach": "@body('Parse_JSON')",
                "runAfter": {
                    "Parse_JSON": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Id",
                            "type": "integer"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Parse_JSON": {
                "inputs": {
                    "content": "@outputs('Compose')",
                    "schema": {
                        "items": {
                            "properties": {
                                "data": {
                                    "properties": {
                                        "type": {
                                            "type": "string"
                                        },
                                        "urls": {
                                            "items": {
                                                "type": "string"
                                            },
                                            "type": "array"
                                        }
                                    },
                                    "type": "object"
                                },
                                "id": {
                                    "type": "integer"
                                },
                                "modify_by": {
                                    "type": "string"
                                },
                                "modify_time": {
                                    "type": "string"
                                },
                                "modify_type": {
                                    "type": "string"
                                },
                                "name": {
                                    "type": "string"
                                },
                                "pending": {
                                    "type": "integer"
                                }
                            },
                            "required": [
                                "id",
                                "name",
                                "data",
                                "modify_by",
                                "modify_time",
                                "modify_type",
                                "pending"
                            ],
                            "type": "object"
                        },
                        "type": "array"
                    }
                },
                "runAfter": {
                    "Compose": [
                        "Succeeded"
                    ]
                },
                "type": "ParseJson"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

【讨论】:

    猜你喜欢
    • 2022-08-19
    • 2019-09-20
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多