2017-05-25 63 views
0

這看起來很明顯,但不知何故它不適合我。我試圖在Microsoft Azure上的Logic App中構建解決方案,但我堅持將JSON對象轉換爲XML。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 
     }] 
} 
} 

上面的響應,然後在「創建的Blob」行動用來保存在Azure上的斑點響應。

link說,邏輯應用程序提供XML函數的字符串或JSON對象轉換爲XML,但這似乎預計將無法正常工作。我想下面的表達,但沒有任何工程,

  1. @xml(體( 'Execute_stored_procedure') '結果集'])

錯誤:模板語言功能 'XML' 參數無效。提供的值不能轉換爲XML:'此文檔已經有'DocumentElement'節點。'。有關使用詳情,請參閱https://aka.ms/logicexpressions#xml

  • @xml(體( 'Execute_stored_procedure')[ '的ResultSets'] [ '表1']?)
  • ERROR:模板語言功能 'XML' 預計它的參數是一個字符串或一個對象。提供的值是'Array'類型。有關使用詳情,請參閱https://aka.ms/logicexpressions#xml

    我要的就是這個JSON轉換爲XML像下面,

    <Root><Product>....</Product><Product>....</Product></Root> 
    

    的替代解決方案,可以調用Azure的功能,這JSON轉換成XML在C#代碼。但在我嘗試替代解決方案之前,我想知道我做錯了什麼。

    回答

    1

    發佈問題後,我進一步分析問題,發現我傳遞錯誤的JSON對象@xml功能。

    正確的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 
         }] 
    } 
    } 
    

    請注意,我有以下刪除到行,

    "OutputParameters": { }, 
    "ReturnCode": 0, 
    

    因此,與嘗試下面的表達和它的工作,

    @xml(json(concat('{\"ResultSets\":',body('Execute_stored_procedure').ResultSets,'}'))) 
    

    現在我需要小調整這個表達式得到最終的XML。希望這可以幫助某人。