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

标签 json azure azureservicebus azure-logic-apps

我想将从 Azure 逻辑应用 中的 http 事件收到的下面提到的 JSON 响应传输到 Azure 服务总线队列

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

我使用了许多表达式,例如 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.

以下是图片:

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

  2. 步骤中的表达式,将json转换为字符串,但正在寻找foreach:https://github.com/arindam-b/images/blob/master/Logicapp2.PNG

  3. 第 2 步完整 View (含服务总线部分):https://github.com/arindam-b/images/blob/master/Logicapp3.PNG

非常感谢您的宝贵意见。

最佳答案

首先,您的 JSON 响应位于 application/json 中,您可以执行 for_each 操作,如下图所示。假设您想向服务总线发送消息。 For_each 输入是 triggerbody() ,消息内容取决于您需要选择 json 数据中的属性。我的测试内容是 body 属性,因此它应该是 items('Fior_each')['body']

enter image description here

第二个场景是文本/纯文本或其他类型的 json 响应,在这种情况下,使用 Request Body JSON Schema 是行不通的。您必须将它们解析为 json 类型,然后选择属性。流程将如下图所示。 Parse_JSON 输入为 triggerbody()for_each 输入为 body('Parse_JSON')

enter image description here

在我问您是否要将整个 json 传输到消息之前,您确认了这一点,但是从您的描述和图片来看,您想要剪切 json 数据并选择您想要的属性。因此,如果您想存储整个 json,则可以不使用 schema 来存储它。

enter image description here

关于json - Azure - 逻辑应用程序到服务总线 - JSON 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58344855/

相关文章:

c# - 通知中心传递失败 C#

azure - 尝试安装 'npm' 时的 LUIS 应用程序 : "Kudu Sync" is not recognized as an internal or external command,

c# - ReceiveAsync 和 OnMessageAsync 之间的差异

java - 在 Java 上获取 XML 或 Json 的代码

ios - Alamofire 4 URL请求参数编码为JSON

javascript - 使用 ko.mapping.fromJS 进行异步 ajax 调用后更新可观察的 knockout

javascript - 在express js中下载多个blob?

azure - 在向 Azure 主题发送消息之前重新创建主题客户端是否是一个好习惯

azure - 在我的应用服务中使用托管标识时,Azure 服务总线的连接字符串的正确格式是什么?

javascript - "Exporting"使用支流对象的支流示例 - d3.js