首页 > 解决方案 > 逻辑应用程序-如何从动态属性名称中检索 json 数据

问题描述

这是我的 json - 在这里我想从“属性 - 动态内容”中检索 json 内容。其中,动态内容部分可能因每个 json 请求而异。如何按动态名称过滤?

{
  "Attributes": 
  {
    "Property1": {
      "Data1": {
        "Value": "50"
  }
},
"Property2": {
  "Data2": {
    "Value": "50"
  }
},
"Property - Dynamic content": {
  "Data3": {
    "Value": "50"
  },
  "Data4": {
    "Value": "50"
  }
}

} }

标签: azure-logic-apps

解决方案


对于您的要求,请参阅下面的我的逻辑应用程序:

1.我初始化了一个变量并存储了与你相同的json来模拟你的情况。

在此处输入图像描述

2.然后使用“解析 JSON ”。

在此处输入图像描述

请注意“ Parse JSON ”的架构显示为:

{
    "properties": {
        "Attributes": {
            "properties": {
                "Property - Dynamic content": {
                    "type": [
                        "object",
                        "array"
                    ]
                },
                "Property1": {
                    "properties": {
                        "Data1": {
                            "properties": {
                                "Value": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "type": "object"
                },
                "Property2": {
                    "properties": {
                        "Data2": {
                            "properties": {
                                "Value": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

请注意上面架构中的typeof Property - Dynamic content。由于 的内容Property - Dynamic content是“对象”或“数组”,所以我将“对象”和“数组”都设置typeProperty - Dynamic content

3.然后我初始化了一个名为“result”的变量来得到你想要的值。 在此处输入图像描述

由于我们在 的架构中同时使用类型“对象”和“数组” Property - Dynamic content,因此您可能在“动态内容”选择中找不到它。您可以通过表达式输入其值,如上面的屏幕截图。整个表达式是:body('Parse_JSON')?['Attributes']?['Property - Dynamic content']


推荐阅读