如何在逻辑应用程序中循环遍历数组?

2024-02-26

我已设法将所有用户数据放入数组中(请参阅here https://stackoverflow.com/questions/59107093/how-to-store-all-azure-ad-user-group-members-in-an-array-using-a-logic-app)但现在我无法循环数据。构建数组后,我已将其转换为 JSON,但我无法再处理 JSON 架构中定义的字段。

我在循环中唯一可以解决的问题(我使用 JSON 正文作为 For Each 循环的输入)是正文本身,而不是用户名、邮件地址等各个字段。

我是否应该更改 JSON 模式中的某些内容来解决此问题,还是有其他问题?

编辑:请在下面找到我的 JSON 架构:

   {
       "$schema": "http://json-schema.org/draft-04/schema#",
       "items": [
           {
               "properties": {
                   "@@odata.type": {
                       "type": "string"
                   },
                   "createdDateTime": {
                       "type": "string"
                   },
                   "employeeId": {
                       "type": "string"
                   },
                   "givenName": {
                       "type": "string"
                   },
                   "id": {
                       "type": "string"
                   },
                   "mail": {
                       "type": "string"
                   },
                   "onPremisesSamAccountName": {
                       "type": "string"
                   },
                   "surname": {
                       "type": "string"
                   },
                   "userPrincipalName": {
                       "type": "string"
                   }
               },
               "required": [
                   "@@odata.type",
                   "id",
                   "givenName",
                   "surname",
                   "userPrincipalName",
                   "mail",
                   "onPremisesSamAccountName",
                   "employeeId",
                   "createdDateTime"
               ],
               "type": "object"
           }
       ],
       "type": "array"
   }

请参阅图片了解 JSON 的外观:


根据我的理解,您只想循环数组来获取每个项目的名称、邮件和其他一些字段。正如您在问题中提到的,您可以使用 json 正文作为 For Each 循环的输入。没关系,不需要再做什么了。请参考下面的截图:

  1. Initialize a variable like your json data. enter image description here

  2. Then parse it by "Parse JSON" action. enter image description here

  3. Now, set the body as input for the For each loop, and then use a variable and set the value with "mail" from "Parse JSON". enter image description here

  4. After running the logic app, we can see the mail field is also looped. You can use the "mail", "name" and other fields easily in your "For each". enter image description here enter image description here

Update:

I checked your json schema, but it seems can't match the json data you provided in your screenshot. May I know how did you generate your json schema, in my side I generate the json schema just by clicking the "Use sample payload to generate schema" button and it will generate the schema automatically. enter image description here

我使用了一个与你的结构相同的json数据样本并生成了它的schema,请参考下面的json数据和schema:

json数据:

{
    "body": [
        {
            "@odata.type": "test",
            "id": "123456",
            "givenName": "test",
            "username": "test",
            "userPrincipalName": "test",
            "mail": "[email protected] /cdn-cgi/l/email-protection",
            "onPremisesSamAccountName": "test",
            "employeeId": "test",
            "createdDateTime": "testdate"
        },
        {
            "@odata.type": "test",
            "id": "123456",
            "givenName": "test",
            "username": "test",
            "userPrincipalName": "test",
            "mail": "[email protected] /cdn-cgi/l/email-protection",
            "onPremisesSamAccountName": "test",
            "employeeId": "test",
            "createdDateTime": "testdate"
        }
    ]
}

schema:

{
    "type": "object",
    "properties": {
        "body": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "@@odata.type": {
                        "type": "string"
                    },
                    "id": {
                        "type": "string"
                    },
                    "givenName": {
                        "type": "string"
                    },
                    "username": {
                        "type": "string"
                    },
                    "userPrincipalName": {
                        "type": "string"
                    },
                    "mail": {
                        "type": "string"
                    },
                    "onPremisesSamAccountName": {
                        "type": "string"
                    },
                    "employeeId": {
                        "type": "string"
                    },
                    "createdDateTime": {
                        "type": "string"
                    }
                },
                "required": [
                    "@@odata.type",
                    "id",
                    "givenName",
                    "username",
                    "userPrincipalName",
                    "mail",
                    "onPremisesSamAccountName",
                    "employeeId",
                    "createdDateTime"
                ]
            }
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在逻辑应用程序中循环遍历数组? 的相关文章

随机推荐