我想将从 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.
以下是图片:
逻辑作为 webhook 收到的 json 响应:https://github.com/arindam-b/images/blob/master/Logicapp1.PNG
步骤中的表达式,将json转换为字符串,但正在寻找foreach:https://github.com/arindam-b/images/blob/master/Logicapp2.PNG
第 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']
。
第二个场景是文本/纯文本或其他类型的 json 响应,在这种情况下,使用 Request Body JSON Schema
是行不通的。您必须将它们解析为 json 类型,然后选择属性。流程将如下图所示。 Parse_JSON
输入为 triggerbody()
,for_each
输入为 body('Parse_JSON')
。
在我问您是否要将整个 json 传输到消息之前,您确认了这一点,但是从您的描述和图片来看,您想要剪切 json 数据并选择您想要的属性。因此,如果您想存储整个 json,则可以不使用 schema 来存储它。
关于json - Azure - 逻辑应用程序到服务总线 - JSON 传输,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58344855/