逻辑应用程序 - 从 json 中获取特定子字符串的表达式

Logic App - Expression to get a particular substring from a json

我完成了逻辑应用程序中的一项任务:

{
"headers": {
    "Connection": "close",
    "Content-Type": "application/json"
},
"body": {
    "systemAlertId": "....",
    "endTimeUtc": null,
    "entities": [
        {
            "$id": "us_1",
            "hostName": "...",
            "azureID": "someID",
            "type": "host"
        },
        {
            "$id": "us_2",
            "address": "fwdedwedwedwed",
            "location": {
                "countryCode": "",
            },
            "type": "ip"
        },
    ], 
}
}

我需要初始化一些名为 resourceID 的变量,其中包含从上面的示例中读取的值 someID

Value someID 总是会在 Entities 数组的第一个成员中找到,在这种情况下我想需要使用函数 first

知道初始变量的表达式应该是什么样子吗?

谢谢

看看Parse JSON action

To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.

有了对象中可用的 JSON 中的信息,您可以更轻松地访问它。

考虑到您从 Http 触发器接收到的上述数据,我使用了 Parse JSON 来获取上述 JSON 的内部值。以下是您的操作方法。

现在您可以使用 'Initialise variable' 连接器初始化 resourceID,并根据您的要求将其值设置为 azureID。