You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Logic App生成Teams Webhook JSON时引号转义问题求助

解决Azure Logic App中Teams Webhook JSON格式错误问题

问题根源

你当前的做法是将拼接好的JSON字符串直接插入到facts数组中,Logic App会将其识别为字符串类型,因此自动在外层添加引号并转义内部所有双引号,导致facts变成了一个包含单个字符串元素的数组,而非预期的对象数组,触发JSON结构错误。

正确解决方案

使用Logic App的@json()函数将拼接好的字符串解析为JSON对象数组,替代直接插入字符串的方式。具体步骤如下:

  1. 确保变量格式合法
    先确认MessageString变量最终生成的是完整的JSON数组字符串,例如:

    [{"2023-08-29T22:00:22.888Z": "ERROR: KHM: 2023-08-29 18:00:22.547 - kinatrax-monitor-server-processes.ps1: Poller service docker container innovation-fsb-kinatrax-poller-service is not running"}, {"2023-08-29T22:00:22.322Z": "ERROR: KHM: 2023-08-29 18:00:22.042 - kinatrax-monitor-server-processes.ps1: Processes not running = KinaTrax_Acquisition, node:kinatrax-store-server-service,KinatraxCameraService"}]
    

    若之前拼接时仅生成了{"time":"msg"},{"time2":"msg2"}这类无包裹的对象列表,需要在变量首尾添加[和],确保是标准JSON数组格式。

  2. 修正Logic App JSON配置
    将原配置中facts字段的表达式用@json()包裹,直接返回解析后的JSON数组:

    {
      "sections": [
        {
          "facts": "@json(substring(variables('MessageString'), 0, sub(length(variables('MessageString')), 1)))",
          "title": "BatFitting 2.0 Dev - Alerts"
        }
      ],
      "summary": "BatFitting 2.0 Dev - Alerts"
    }
    

    注意:这里不再需要将表达式放在数组[]中,因为@json()返回的本身就是数组,直接赋值给facts即可。

验证效果

配置修正后,Logic App会将MessageString解析为JSON对象数组,最终生成的Teams webhook请求体将符合你预期的格式:

{
  "sections": [
    {
      "facts": [
        {"2023-08-29T22:00:22.888Z": "ERROR: KHM: 2023-08-29 18:00:22.547 - kinatrax-monitor-server-processes.ps1: Poller service docker container innovation-fsb-kinatrax-poller-service is not running"},
        {"2023-08-29T22:00:22.322Z": "ERROR: KHM: 2023-08-29 18:00:22.042 - kinatrax-monitor-server-processes.ps1: Processes not running = KinaTrax_Acquisition, node:kinatrax-store-server-service,KinatraxCameraService"}
      ],
      "title": "BatFitting 2.0 Dev - Alerts"
    }
  ],
  "summary": "BatFitting 2.0 Dev - Alerts"
}

内容的提问来源于stack exchange,提问作者Westy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 04:54:52