azure - 如何在azure逻辑应用程序中获取json http响应的值

标签 azure azure-logic-apps

我试图通过解析下面的输出示例来将“id”值设置为变量。 REST API 调用将返回多个值,如下所示,我只想获取用户之前通过参数值或初始化变量在工作流程中提供/设置为输入的特定名称的“id”值。如何在 azure 逻辑应用中执行此值提取?

非常感谢任何帮助。

[
  {
    "id": 1,
    "name": "xyz-List",
    "data": {
      "urls": [
        "*.test1.com",
        "*.test2.com"
      ],
      "type": "exact"
    },
    "modify_by": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6100050c080f2119181b4f020e0c" rel="noreferrer noopener nofollow">[email protected]</a>",
    "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6c0d080105022c141516420f0301" rel="noreferrer noopener nofollow">[email protected]</a>",
    "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="28494c45414668505152064b4745" rel="noreferrer noopener nofollow">[email protected]</a>",
    "modify_time": "2022-09-26T01:25:20.000Z",
    "modify_type": "Edited",
    "pending": 0
  }
]

最佳答案

我已经从我的末端进行了复制,并且可以通过解析您的 REST API 调用值来使其工作。为了迭代解析的 JSON,我使用了 for-each 循环,并使用以下表达式提取了 Id 并将其值设置为变量。

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

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

enter image description here

结果:

enter image description here

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

{
    "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5a4a1a8acab85bdbcbfeba6aaa8" rel="noreferrer noopener nofollow">[email protected]</a>",
                        "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="48292c25212608303132662b2725" rel="noreferrer noopener nofollow">[email protected]</a>",
                        "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f796939a9e99b78f8e8dd994989a" rel="noreferrer noopener nofollow">[email protected]</a>",
                        "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": {}
}

关于azure - 如何在azure逻辑应用程序中获取json http响应的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73859569/

相关文章:

node.js - 无法在Azure应用程序服务上部署React JS应用程序

python - 创建 blob 时如何在 azure 中触发事件触发函数

azure - 从 LogicApp 使用 "Send a HTTP Request to DevOps"时获取身份验证错误

azure-logic-apps - 允许编辑链接到集成帐户的逻辑应用

Azure 逻辑应用列表 Blob List_Blob 元数据字段值是什么

azure - 通过 Multi-Tenancy Azure AD 应用程序中的访问 token 唯一标识用户

azure - 如何从 Azure Functions 通过 SSH 连接到 Azure VM?

azure - Windows Azure 本地测试

azure - API 连接失败,错误代码为 'Forbidden'

azure-logic-apps - 逻辑应用将 "null"替换为 "",反之亦然