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/

相关文章:

caching - 异步数据缓存 API (.NET)

c# - Windows Azure 服务总线计费

json - 如何迭代 JSON 数组以在 jasperreports 中创建重复报告

ios - 使用带有添加的 WebAPI 参数的 NSDictionary

html - 在脚本标签中嵌入 JSON 对象

c# - Azure 主题辅助角色在 60 秒后停止处理消息

python - 使用 Python 创建 D3 嵌套 JSON 数据

python - Azure是否允许应用程序需要OpenGL,有什么办法可以解决吗?

c# - 有没有办法使 Azure WebJobs ServiceBus 输出参数可选?

file - 是否可以将文件发送到 Azure 事件中心?