如何在逻辑应用程序中遍历数组? [英] How to loop through an array in a logic app?

查看:81
本文介绍了如何在逻辑应用程序中遍历数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法将所有用户数据存储在一个数组中(请参阅

I have managed to get all my userdata in an array (see here) but now I cannot loop through the data. After building the array I have converted it to JSON, but I can no longer address the fields as defined in my JSON schema.

我在循环中唯一能解决的问题(我将JSON主体用作For Each循环的输入)是主体本身,而不是诸如用户名,邮件地址等单个字段.

The only thing I can address in my loop (I use the JSON body as input for the For Each loop) is the body itself, not the individual fields like username, mail address etc.

我应该更改JSON模式中的某些内容以解决此问题还是其他错误吗?

Should I change something in my JSON schema to overcome this or is something else wrong?

请在下面找到我的JSON模式:

Please find my JSON schema below:

   {
       "$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的外观:

Please see the image for how the JSON looks:

推荐答案

根据我的理解,您只想循环数组以获取每个项目的名称,邮件和其他一些字段.正如您在问题中提到的那样,您可以将json主体用作For Each循环的输入.没关系,无需再做任何其他事情.请参考以下屏幕截图:

Per my understanding, you just want to loop your array to get each item's name, mail and some other fields. As you mentioned in your question, you can use the json body as input for the For Each loop. It's ok, ther is not need to to anything more. Please refer to the screenshot below:

  1. 初始化一个变量,例如json数据.

  1. Initialize a variable like your json data.

然后通过解析JSON"操作对其进行解析.

Then parse it by "Parse JSON" action.

现在,将主体设置为For each循环的输入,然后使用一个变量,并使用"Parse JSON"中的"mail"设置值.

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".

运行逻辑应用程序后,我们可以看到邮件字段也已循环.您可以在对于每个"中轻松使用邮件",名称"和其他字段.

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".

更新:

我检查了您的json模式,但似乎与您在屏幕截图中提供的json数据不匹配.我想知道您是如何生成json模式的,在我这边,只需单击"使用示例有效负载生成模式"按钮即可生成json模式,它将自动生成模式.

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.

我使用与您的结构相同的json数据示例并生成其架构,请参考以下json数据和架构:

I use a json data sample with the same structure of yours' and generate its schema, please refer to the json data and schema below:

json数据:

{
    "body": [
        {
            "@odata.type": "test",
            "id": "123456",
            "givenName": "test",
            "username": "test",
            "userPrincipalName": "test",
            "mail": "test@mail.com",
            "onPremisesSamAccountName": "test",
            "employeeId": "test",
            "createdDateTime": "testdate"
        },
        {
            "@odata.type": "test",
            "id": "123456",
            "givenName": "test",
            "username": "test",
            "userPrincipalName": "test",
            "mail": "test@mail.com",
            "onPremisesSamAccountName": "test",
            "employeeId": "test",
            "createdDateTime": "testdate"
        }
    ]
}

模式:

{
    "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"
                ]
            }
        }
    }
}

这篇关于如何在逻辑应用程序中遍历数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆