在电源自动化内部将 JSON 转换为数组时出错“无法处理行中操作“Compose_2”输入中的模板语言表达式

问题描述 投票:0回答:1

我有一个包含此内容的文件,我正在将文件内容解析为 JSON:-

{
  "OOH.wu.2023.9.53": {
    "Brand": "***",
    "Contract Number": "OOH.wu.2023.9.53",
    "Client Name": "****",
    "Sector": "FOODS",
    "Media_list": [
      {
        "Network": "****",
        "Amount": "4000.000",
        "Duration": "1 Month",
        "of_Faces": "1",
        "Start_Date": "01-Oct-2023",
        "End_Date": "01-Nov-2023",
        "Delivery Date": "01-Oct-2023"
      },
      {
        "Network": "****",
        "Amount": "4800.000",
        "Duration": "1 Month",
        "of_Faces": "1",
        "Start_Date": "01-Oct-2023",
        "End_Date": "01-Nov-2023",
        "Delivery Date": "01-Oct-2023"
      },
      {
        "Network": "****",
        "Amount": "4250.000",
        "Duration": "1 Month",
        "of_Faces": "1",
        "Start_Date": "01-Oct-2023",
        "End_Date": "01-Nov-2023",
        "Delivery Date": "01-Oct-2023"
      }
    ],
    "No of Faces": "3"
  },
  "OOH.wu.2023.7.50": {
    "Brand": "****",
    "Contract Number": "OOH.wu.2023.7.50",
    "Client Name": "****",
    "Sector": "****",
    "Media_list": [
      {
        "Network": "****",
        "Amount": "4250.000",
        "Duration": null,
        "of_Faces": "1",
        "Start_Date": "14-Aug-2023",
        "End_Date": "14-Sep-2023",
        "Delivery Date": "14-Aug-2023"
      },
      {
        "Network": "****",
        "Amount": "4250.000",
        "Duration": null,
        "of_Faces": "1",
        "Start_Date": "09-Aug-2023",
        "End_Date": "09-Sep-2023",
        "Delivery Date": "09-Aug-2023"
      }
    ],
    "No of Faces": "2"
  }
  
}

然后我尝试将 JSON 转换为数组,以便能够在 json 中ApplyToEach 项目,所以我按照以下步骤操作:

  1. 我在“解析 JSON”操作之后添加了一个撰写操作,使用此公式
    xpath(xml(body('Parse_JSON')), '/root/*')
    ,如下:-

但是我收到了这个错误:-

InvalidTemplate. Unable to process template language expressions in action 'Compose_2' inputs at line '0' and column '0': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifying a DeserializeRootElementName. Path 'outputs.body['OOH.wu.2023.9.53']'.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.

有什么建议吗?谢谢

json xml xpath power-automate power-platform
1个回答
0
投票

错误消息清楚地说明了错误是什么。与 JSON 不同,XML 必须具有一个根元素,而在您的情况下,JSON 具有多个根元素。

尝试以下操作:

xpath(xml(concat('{"contracts":', string(body('Parse_JSON')), '}')), '/root/*')
© www.soinside.com 2019 - 2024. All rights reserved.