将 SQL 存储过程 ResultSet 表 JSON 转换为 XML

pgc*_*can 4 azure azure-logic-apps azure-sql-database

这看起来很明显,但不知何故它对我不起作用。我正在尝试在 Microsoft Azure 上的 Logic App 中构建解决方案,但我坚持将 JSON 对象转换为 XML。

我的要求是执行存储过程并以 XML 格式保存响应。默认情况下,SQL 执行存储过程操作以以下 JSON 格式返回响应,

    {
"OutputParameters": { },
"ReturnCode": 0,
"ResultSets": {
"Table1": [
      {
        "ProductID": 680,
        "Name": "HL Road Frame - Black, 58",
        "ProductNumber": "FR-R92B-58",
        "Color": "Black",
        "StandardCost": 1059.31,
        "ListPrice": 1431.5,
        "Size": "58",
        "Weight": 1016.04
      },
      {
        "ProductID": 706,
        "Name": "HL Road Frame - Red, 58",
        "ProductNumber": "FR-R92R-58",
        "Color": "Red",
        "StandardCost": 1059.31,
        "ListPrice": 1431.5,
        "Size": "58",
        "Weight": 1016.04
      }]
 }
}
Run Code Online (Sandbox Code Playgroud)

然后在“创建 Blob”操作中使用上述响应以在 Azure 上的 Blob 中保存响应。

链接表示逻辑应用程序提供了 xml 函数来将字符串或 JSON 对象转换为 XML,但这似乎没有按预期工作。我试过下面的表达,但没有任何效果,

  1. @xml(body('Execute_stored_procedure')?['ResultSets'])

错误:模板语言函数“xml”参数无效。提供的值无法转换为 XML:“此文档已经有一个 'DocumentElement' 节点。”。有关使用详细信息,请参阅https://aka.ms/logicexpressions#xml

  1. @xml(body('Execute_stored_procedure')?['ResultSets']['Table1'])

错误:模板语言函数“xml”要求其参数为字符串或对象。提供的值属于“数组”类型。有关使用详细信息,请参阅https://aka.ms/logicexpressions#xml

我想要的只是将此 JSON 转换为如下所示的 XML,

<Root><Product>....</Product><Product>....</Product></Root>
Run Code Online (Sandbox Code Playgroud)

替代解决方案可能是调用 Azure 函数并将此 JSON 转换为 C# 代码中的 XML。但在我尝试替代解决方案之前,我想知道我做错了什么。

pgc*_*can 5

发布问题后,我进一步分析了问题,发现我在@xml 函数中传递了错误的 JSON 对象。

正确的 JSON 对象应如下所示,

{
"ResultSets": {
"Table1": [
      {
        "ProductID": 680,
        "Name": "HL Road Frame - Black, 58",
        "ProductNumber": "FR-R92B-58",
        "Color": "Black",
        "StandardCost": 1059.31,
        "ListPrice": 1431.5,
        "Size": "58",
        "Weight": 1016.04
      },
      {
        "ProductID": 706,
        "Name": "HL Road Frame - Red, 58",
        "ProductNumber": "FR-R92R-58",
        "Color": "Red",
        "StandardCost": 1059.31,
        "ListPrice": 1431.5,
        "Size": "58",
        "Weight": 1016.04
      }]
 }
}
Run Code Online (Sandbox Code Playgroud)

请注意,我必须删除下面的行,

"OutputParameters": { },
"ReturnCode": 0,
Run Code Online (Sandbox Code Playgroud)

所以尝试了下面的表达式,它奏效了,

@xml(json(concat('{\"ResultSets\":',body('Execute_stored_procedure').ResultSets,'}')))
Run Code Online (Sandbox Code Playgroud)

现在我需要稍微调整这个表达式以获得最终的 XML。希望这可以帮助某人。