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

Logic Apps中JSON数组与响应问题:CostsCalculation数组错误重复求助

解决Logic Apps中CostsCalculation重复数据的问题

问题根源

当前流程未针对每个服务的成本查询结果做空值判断,导致无成本数据时复用了之前循环的非空结果,而非设置为空数组。

调整方案

  1. 为成本查询结果添加空值判断
    在查询当前服务的成本费率后,立即通过表达式判断结果是否为空。在构建每个服务的报价对象时,动态赋值CostsCalculation:

    • 使用 if(empty(body('查询成本费率')), [], body('查询成本费率')) 表达式,当成本查询返回空时,设置为空数组;否则使用查询到的费率数据。
  2. 重构对象构建逻辑
    不要直接追加数组元素,改为为每个服务单独构建完整的报价对象,再将对象加入最终数组:

    • 遍历活跃服务,获取当前服务的销售费率并暂存
    • 查询当前服务对应的成本费率
    • 通过Compose步骤创建单个服务的报价对象,示例表达式:
      {
        "ChargeCode": @items('遍历服务')?['ChargeCode'],
        "ChargeDescription": "",
        "ChargesCalculation": @body('获取销售费率'),
        "CostsCalculation": @if(empty(body('查询成本费率')), [], body('查询成本费率')),
        "Currency": "USD"
      }
      
    • 将Compose的输出追加到最终的报价数组中

调整后预期输出

[
  {
    "ChargeCode": "Carge2",
    "ChargeDescription": "",
    "ChargesCalculation": [
      {
        "base": null,
        "break": null,
        "calculationType": "COS",
        "currency": "GBP",
        "max": null,
        "min": null,
        "rate": 1000
      }
    ],
    "CostsCalculation": [
      {
        "base": null,
        "break": null,
        "calculationType": "CTN",
        "currency": "USD",
        "max": null,
        "min": null,
        "rate": 27000
      }
    ],
    "Currency": "USD"
  },
  {
    "ChargeCode": "Charge1",
    "ChargeDescription": "",
    "ChargesCalculation": [
      {
        "base": null,
        "break": null,
        "calculationType": "FLT",
        "currency": "GBP",
        "max": null,
        "min": null,
        "rate": 50
      }
    ],
    "CostsCalculation": [],
    "Currency": "USD"
  }
]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 09:10:27