我想拆分字符串并作为复杂的 json 字符串传递以使用逻辑应用程序形成自定义字段
I want to split string and passed as complex json string to form custom field using logic app
我有如下字符串值:
demo1 = "A:3 ; B:2"
demo2 = "A:3 ; Z:1 ; T:4"
main = "thisDemoIsNew"
我想使用上面的 demo1 和 demo2 从 main
字符串中拆分值。
例如 - 对于 demo1,我将生成如下所示的新字符串
NewString = "A:thi ; B:sD"
我想使用逻辑应用来完成。
demo1 显示 A:3 和 B:2,这里 3 和 2 是我们将从 main
字符串变量中获取的长度。
例如,对于 demo2,我将生成如下所示的新字符串
新字符串 = "A:thi ; Z:s ; T:Demo"
我想使用逻辑应用来完成。
demo2 显示 A:3 ; Z:1; T:4 这里的 3 ,1 和 4 是我们将从 main
字符串变量中获取的长度。
如何在逻辑应用程序中实现这一点我可以采用新变量进行拆分,但应该根据 demo1 和 demo2 的长度拆分表达式。
感觉这是一种过于复杂的方法,但是,我进行了一些转换,首先将其转换为 JSON,然后在每个循环中使用 [=10 附加到一个变量中=] 和 degree of parallelism set to 1
.
我已经在每个动作的评论中包含了所有的表达和拆分。
现在,如果你想一次性为 Demo1 和 Demo2 制作这个,你需要包装我的解决方案来处理数组。
编辑:我意识到我因此创建了一个数组,但是当你已经做到这一点时,你可以很容易地把它全部附加到一个字符串中。
代码连接信息,它同时包含一个驱动器和一个存储 blob,当前连接到一个存储 blob,最终输出到 excel table:
{
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/azureblob"
},
"excelonlinebusiness": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/excelonlinebusiness",
"connectionName": "excelonlinebusiness",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/excelonlinebusiness"
},
"onedriveforbusiness": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/onedriveforbusiness",
"connectionName": "onedriveforbusiness",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/onedriveforbusiness"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@body('Get_blob_content')",
"runAfter": {
"Get_blob_content": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each_row": {
"actions": {
"Add_a_row_into_a_table": {
"inputs": {
"body": {
"Hours": "@body('Parse_JSON')?['PackageServiceId']",
"Id": "@body('Parse_JSON')?['ActiveUsers']",
"Name": "@body('Parse_JSON')?['AgreementID']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['excelonlinebusiness']['connectionId']"
}
},
"method": "post",
"path": "/codeless/v1.2/drives/@{encodeURIComponent('[Some long hash]')}/items/@{encodeURIComponent('[Some long hash]')}/workbook/tables/@{encodeURIComponent('{[GUID]}')}/rows",
"queries": {
"source": "me"
}
},
"metadata": {
"[Some long hash]": "/LOL/Bok1.xlsx"
},
"runAfter": {
"clear_tempArray_for_next_row": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Clear_data_of_special_characters": {
"description": "replace(replace(replace(item(),'[',''),']',''),'\"','')",
"inputs": {
"name": "data",
"value": "@{replace(replace(replace(item(),'[',''),']',''),'\"','')}"
},
"runAfter": {},
"type": "SetVariable"
},
"For_each_item_on_row": {
"actions": {
"Append_to_tempArray": {
"description": "Create array to hold values before compose and json",
"inputs": {
"name": "tempArray",
"value": "@items('For_each_item_on_row')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"description": "split(variables('data'),',')",
"foreach": "@split(variables('data'),',')",
"runAfter": {
"Clear_data_of_special_characters": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"description": "Parse into json object",
"inputs": {
"content": "@variables('data')",
"schema": {
"properties": {
"ActiveUsers": {
"type": "string"
},
"AgreementID": {
"type": "string"
},
"PackageServiceId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Set_data_to_json_formated_string": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Set_data_to_json_formated_string": {
"description": "Create json string using tempArray: variables('tempArray')?[0] throu variables('tempArray')?[2]",
"inputs": {
"name": "data",
"value": "{\n\"AgreementID\":\"@{variables('tempArray')?[0]}\",\n\"PackageServiceId\":\"@{variables('tempArray')?[1]}\",\n\"ActiveUsers\":\"@{variables('tempArray')?[2]}\"\n}"
},
"runAfter": {
"For_each_item_on_row": [
"Succeeded"
]
},
"type": "SetVariable"
},
"clear_tempArray_for_next_row": {
"inputs": {
"name": "tempArray",
"value": "@null"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"description": "split on newline in csv doc. @split(body('Get_file_content'),'\r\n')",
"foreach": "@split(outputs('Compose'),'\r\n')",
"runAfter": {
"Initialize_'data'_string": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Get_blob_content": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('[Some long hash]'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"[Some long hash]": "/Whosebug/blob.csv"
},
"runAfter": {
"Get_file_content": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Get_file_content": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('[Some long hash]'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"[Some long hash].[Some long hash]": "/LOL/Bok1.csv",
"[Some long hash].[Some long hash]": "/LOL/Bok1.xlsx",
"[Some long hash].[Some long hash]": "/LOL/ReadStuff.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_'data'_string": {
"inputs": {
"variables": [
{
"name": "data",
"type": "String"
}
]
},
"runAfter": {
"Initialize_'tempArray'_array": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_'tempArray'_array": {
"inputs": {
"variables": [
{
"name": "tempArray",
"type": "Array"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Month",
"interval": 3
},
"type": "Recurrence"
}
}
}
}
我有如下字符串值:
demo1 = "A:3 ; B:2"
demo2 = "A:3 ; Z:1 ; T:4"
main = "thisDemoIsNew"
我想使用上面的 demo1 和 demo2 从 main
字符串中拆分值。
例如 - 对于 demo1,我将生成如下所示的新字符串
NewString = "A:thi ; B:sD"
我想使用逻辑应用来完成。
demo1 显示 A:3 和 B:2,这里 3 和 2 是我们将从 main
字符串变量中获取的长度。
例如,对于 demo2,我将生成如下所示的新字符串 新字符串 = "A:thi ; Z:s ; T:Demo"
我想使用逻辑应用来完成。
demo2 显示 A:3 ; Z:1; T:4 这里的 3 ,1 和 4 是我们将从 main
字符串变量中获取的长度。
如何在逻辑应用程序中实现这一点我可以采用新变量进行拆分,但应该根据 demo1 和 demo2 的长度拆分表达式。
感觉这是一种过于复杂的方法,但是,我进行了一些转换,首先将其转换为 JSON,然后在每个循环中使用 [=10 附加到一个变量中=] 和 degree of parallelism set to 1
.
我已经在每个动作的评论中包含了所有的表达和拆分。
现在,如果你想一次性为 Demo1 和 Demo2 制作这个,你需要包装我的解决方案来处理数组。
编辑:我意识到我因此创建了一个数组,但是当你已经做到这一点时,你可以很容易地把它全部附加到一个字符串中。
代码连接信息,它同时包含一个驱动器和一个存储 blob,当前连接到一个存储 blob,最终输出到 excel table:
{
"$connections": {
"value": {
"azureblob": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/azureblob",
"connectionName": "azureblob",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/azureblob"
},
"excelonlinebusiness": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/excelonlinebusiness",
"connectionName": "excelonlinebusiness",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/excelonlinebusiness"
},
"onedriveforbusiness": {
"connectionId": "/subscriptions/[GUID]/resourceGroups/Whosebug/providers/Microsoft.Web/connections/onedriveforbusiness",
"connectionName": "onedriveforbusiness",
"id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/onedriveforbusiness"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@body('Get_blob_content')",
"runAfter": {
"Get_blob_content": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each_row": {
"actions": {
"Add_a_row_into_a_table": {
"inputs": {
"body": {
"Hours": "@body('Parse_JSON')?['PackageServiceId']",
"Id": "@body('Parse_JSON')?['ActiveUsers']",
"Name": "@body('Parse_JSON')?['AgreementID']"
},
"host": {
"connection": {
"name": "@parameters('$connections')['excelonlinebusiness']['connectionId']"
}
},
"method": "post",
"path": "/codeless/v1.2/drives/@{encodeURIComponent('[Some long hash]')}/items/@{encodeURIComponent('[Some long hash]')}/workbook/tables/@{encodeURIComponent('{[GUID]}')}/rows",
"queries": {
"source": "me"
}
},
"metadata": {
"[Some long hash]": "/LOL/Bok1.xlsx"
},
"runAfter": {
"clear_tempArray_for_next_row": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Clear_data_of_special_characters": {
"description": "replace(replace(replace(item(),'[',''),']',''),'\"','')",
"inputs": {
"name": "data",
"value": "@{replace(replace(replace(item(),'[',''),']',''),'\"','')}"
},
"runAfter": {},
"type": "SetVariable"
},
"For_each_item_on_row": {
"actions": {
"Append_to_tempArray": {
"description": "Create array to hold values before compose and json",
"inputs": {
"name": "tempArray",
"value": "@items('For_each_item_on_row')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"description": "split(variables('data'),',')",
"foreach": "@split(variables('data'),',')",
"runAfter": {
"Clear_data_of_special_characters": [
"Succeeded"
]
},
"type": "Foreach"
},
"Parse_JSON": {
"description": "Parse into json object",
"inputs": {
"content": "@variables('data')",
"schema": {
"properties": {
"ActiveUsers": {
"type": "string"
},
"AgreementID": {
"type": "string"
},
"PackageServiceId": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"Set_data_to_json_formated_string": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Set_data_to_json_formated_string": {
"description": "Create json string using tempArray: variables('tempArray')?[0] throu variables('tempArray')?[2]",
"inputs": {
"name": "data",
"value": "{\n\"AgreementID\":\"@{variables('tempArray')?[0]}\",\n\"PackageServiceId\":\"@{variables('tempArray')?[1]}\",\n\"ActiveUsers\":\"@{variables('tempArray')?[2]}\"\n}"
},
"runAfter": {
"For_each_item_on_row": [
"Succeeded"
]
},
"type": "SetVariable"
},
"clear_tempArray_for_next_row": {
"inputs": {
"name": "tempArray",
"value": "@null"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"description": "split on newline in csv doc. @split(body('Get_file_content'),'\r\n')",
"foreach": "@split(outputs('Compose'),'\r\n')",
"runAfter": {
"Initialize_'data'_string": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Get_blob_content": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('[Some long hash]'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"[Some long hash]": "/Whosebug/blob.csv"
},
"runAfter": {
"Get_file_content": [
"Succeeded"
]
},
"type": "ApiConnection"
},
"Get_file_content": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['onedriveforbusiness']['connectionId']"
}
},
"method": "get",
"path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent('[Some long hash]'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"[Some long hash].[Some long hash]": "/LOL/Bok1.csv",
"[Some long hash].[Some long hash]": "/LOL/Bok1.xlsx",
"[Some long hash].[Some long hash]": "/LOL/ReadStuff.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_'data'_string": {
"inputs": {
"variables": [
{
"name": "data",
"type": "String"
}
]
},
"runAfter": {
"Initialize_'tempArray'_array": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_'tempArray'_array": {
"inputs": {
"variables": [
{
"name": "tempArray",
"type": "Array"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"recurrence": {
"frequency": "Month",
"interval": 3
},
"type": "Recurrence"
}
}
}
}