我是 Azure 的新手,必須從邏輯應用接收到的單獨 XML 訊息創建 JSON 陣列。邏輯應用請求資料并接收 XML 格式的回應。我提出了一種方法,將訊息保存在 Azure 存盤中,然后通過 Azure 函式創建 JSON 陣列。這種方法會影響性能嗎?有什么想法嗎?
提前致謝
uj5u.com熱心網友回復:
有兩種方法可以完全依賴邏輯應用而不涉及 Azure 函式
認為這是示例 xml
<?xml version="1.0"?>
<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
<Address Type="Shipping">
<Name>Adam Murphy</Name>
<Street>123 Maple Street</Street>
<City>Mill Valley</City>
<State>CA</State>
<Zip>10999</Zip>
<Country>Ireland</Country>
</Address>
<Address Type="Billing">
<Name>Tai Yee</Name>
<Street>8 Oak Avenue</Street>
<City>Old Town</City>
<State>PA</State>
<Zip>95819</Zip>
<Country>Ireland</Country>
</Address>
<DeliveryNotes />
</PurchaseOrder>
方式一
json(xml(triggerBody()))
您可以使用以下是供您參考的邏輯應用程式直接將 xml 轉換為 json -

輸出

如果您想擁有一個自定義 json,那么您可以使用Parse_Json和Compose連接器創建一個。

在這里,我只是將Compose連接器的輸出Parse_Json用于決議生成的 Json 以獲取自定義 JSON 腳本。下面是我正在嘗試創建的 Json。
{
"PurchaseOrder": {
"OrderNumber": "@{body('Parse_JSON')?['PurchaseOrder']?['@PurchaseOrderNumber']}",
"PurchaseDate": "@{body('Parse_JSON')?['PurchaseOrder']?['@OrderDate']}",
"Location": [
{
"Name": "@{items('For_each')?['Name']}",
"Address": "@{items('For_each')?['Street']},@{items('For_each')?['City']},@{items('For_each')?['State']},@{items('For_each')?['Country']},@{items('For_each')?['Zip']}"
}
]
}
}
輸出


這是我的邏輯應用程式的代碼視圖。您可以直接使用它在邏輯應用中獲取確切的作業流。
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@json(xml(triggerBody()))",
"runAfter": {},
"type": "Compose"
},
"For_each": {
"actions": {
"Compose_2": {
"inputs": {
"PurchaseOrder": {
"Location": [
{
"Address": "@{items('For_each')?['Street']},@{items('For_each')?['City']},@{items('For_each')?['State']},@{items('For_each')?['Country']},@{items('For_each')?['Zip']}",
"Name": "@{items('For_each')?['Name']}"
}
],
"OrderNumber": "@{body('Parse_JSON')?['PurchaseOrder']?['@PurchaseOrderNumber']}",
"PurchaseDate": "@{body('Parse_JSON')?['PurchaseOrder']?['@OrderDate']}"
}
},
"runAfter": {},
"type": "Compose"
}
},
"foreach": "@body('Parse_JSON')?['PurchaseOrder']?['Address']",
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"inputs": {
"content": "@outputs('Compose')",
"schema": {
"properties": {
"?xml": {
"properties": {
"@@version": {
"type": "string"
}
},
"type": "object"
},
"PurchaseOrder": {
"properties": {
"@@OrderDate": {
"type": "string"
},
"@@PurchaseOrderNumber": {
"type": "string"
},
"Address": {
"items": {
"properties": {
"@@Type": {
"type": "string"
},
"City": {
"type": "string"
},
"Country": {
"type": "string"
},
"Name": {
"type": "string"
},
"State": {
"type": "string"
},
"Street": {
"type": "string"
},
"Zip": {
"type": "string"
}
},
"required": [
"@@Type",
"Name",
"Street",
"City",
"State",
"Zip",
"Country"
],
"type": "object"
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
}
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
WAY-2
您可以使用流動模板,以便使用Transform XML to JSON連接器將 xml 轉換為 json。有關更多資訊,您可以參考thread1和thread2。
參考: 邏輯應用程式:基本 XML 到 JSON 運算式轉換
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/434767.html
上一篇:節點xml包不適用于具有:的鍵
