简体   繁体   English

Azure - 逻辑应用程序到服务总线 - JSON 传输

[英]Azure - Logic app to Service Bus - JSON transfer

I want to transfer below mentioned JSON response received from http event in Azure Logic App to Azure Service Bus queue .我要在下面提到JSON收到Z80791B3AE7002CB88C246876D9FAAAA.FAAAA.FAAA8F8F8ZZ3A580F14220377F1F137F138FA138FA1389FAN8SC38FAFA138FAFAINF138FAFAINF138FAIN98FAIN98FAIN98FAIRENFICEN898FAIN98FAIC898FAICEN898FAICEN898FICER

{
  "properties": {
    "data": {
      "properties": {
        "alertContext": {
          "properties": {},
          "type": "object"
        },
        "essentials": {
          "properties": {
            "alertContextVersion": {
              "type": "string"
            },
            "alertId": {
              "type": "string"
            },
            "alertRule": {
              "type": "string"
            },
            "alertTargetIDs": {
              "items": {
                "type": "string"
              },
              "type": "array"
            },
            "description": {
              "type": "string"
            },
            "essentialsVersion": {
              "type": "string"
            },
            "firedDateTime": {
              "type": "string"
            },
            "monitorCondition": {
              "type": "string"
            },
            "monitoringService": {
              "type": "string"
            },
            "originAlertId": {
              "type": "string"
            },
            "resolvedDateTime": {
              "type": "string"
            },
            "severity": {
              "type": "string"
            },
            "signalType": {
              "type": "string"
            }
          },
          "type": "object"
        }
      },
      "type": "object"
    },
    "schemaId": {
      "type": "string"
    }
  },
  "type": "object"
}

I have used many expressions like encodebase64(string(triggerBody())) but it throws error.我使用了许多表达式,例如encodebase64(string(triggerBody()))但它会引发错误。


ExpressionEvaluationFailed. The execution of template action 'For_each' failed: the result of the evaluation of 'foreach' expression '@encodebase64(string(triggerBody()))' is of type 'String'. The result must be a valid array.

Here are the images:以下是图片:

  1. json response received by logic as webhook: https://github.com/arindam-b/images/blob/master/Logicapp1.PNG逻辑作为 webhook 收到的 json 响应: https://github.com/arindam-b/images/blob/master/Logicapp1.PNG

  2. Expression in step, to convert json to string, but is looking for foreach: https://github.com/arindam-b/images/blob/master/Logicapp2.PNG步骤中的表达式,将 json 转换为字符串,但正在寻找 foreach: https://github.com/arindam-b/images/blob/master/Logicapp2.PNG

  3. Step 2 full view with service bus part: https://github.com/arindam-b/images/blob/master/Logicapp3.PNG第 2 步完整视图与服务总线部分: https://github.com/arindam-b/images/blob/master/Logicapp3.PNG

Many thanks for your valuable inputs.非常感谢您的宝贵意见。

Firstly, your JSON response is in application/json , the you could be able to do for_each action, it will be like the below pic.首先,您的 JSON 响应位于application/json中,您可以执行 for_each 操作,如下图所示。 And suppose you want to send message to Service Bus.并假设您想向服务总线发送消息。 The For_each input is triggerbody() and the message content depends you requirement select the property in you json data. For_each 输入是triggerbody()并且消息内容取决于您的要求 select 您 json 数据中的属性。 My test content is the body property so it should be items('Fior_each')['body'] .我的测试内容是body属性,所以它应该是items('Fior_each')['body']

在此处输入图像描述

The second scene is your json response in text/plain or other types, in this situation It won't work you use Request Body JSON Schema .第二个场景是您的 json 以 text/plain 或其他类型的响应,在这种情况下,您使用Request Body JSON Schema将不起作用。 You have to parse them to json type then select property.您必须将它们解析为 json 类型,然后是 select 属性。 The flow will be like the below pic.流程将如下图所示。 The Parse_JSON input is triggerbody() and the for_each input is body('Parse_JSON') . Parse_JSON输入是triggerbody()for_each输入是body('Parse_JSON')

在此处输入图像描述

Before I ask did you want to transfer the whole json to message, you affirm it however from your description and your picture, you want to cut your json data and select the property you want.在我问您是否要将整个 json 转移到消息之前,您确认它但是从您的描述和图片中,您想要剪切您的 json 数据和 select 您想要的属性。 So if you want to store the whole json, you could store it without schema.因此,如果您想存储整个 json,您可以在没有架构的情况下存储它。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM