首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >我想拆分字符串,并将其作为复杂的json字符串传递给使用逻辑应用程序的自定义字段

我想拆分字符串,并将其作为复杂的json字符串传递给使用逻辑应用程序的自定义字段
EN

Stack Overflow用户
提问于 2019-06-26 01:28:07
回答 1查看 2.6K关注 0票数 0

我有如下的字符串值:

代码语言:javascript
复制
demo1 = "A:3 ; B:2"

demo2 = "A:3 ; Z:1 ; T:4"

main = "thisDemoIsNew"

我想使用上面的demo1和demo2从main字符串中拆分值。

例如-对于demo1,我将生成如下所示的新字符串

代码语言:javascript
复制
NewString = "A:thi ; B:sD"

我想用逻辑应用来做这件事。

demo1显示A:3和B:2,这里3和2是长度,我们将从main字符串变量中获取。

例如,对于演示,我将生成如下所示的新字符串NewString = "A:thi;Z:s;T: demo2“

我想用逻辑应用来做这件事。

demo2显示A:3;Z:1;T:4,其中3 ,1和4是我们将从main字符串变量中获取的长度。

如何在逻辑应用程序中实现这一点我可以接受新的变量进行拆分,但应该根据demo1和demo2的长度拆分表达式。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-26 04:53:40

感觉这是一种过于复杂的方法,但是,我经历了几次转换,首先将其转换为JSON,然后使用concurrency set to enableddegree of parallelism set to 1在几个for each循环中附加到一个变量。

我已经在每个操作的注释中包含了所有的表达式和拆分。

现在,如果您想同时处理Demo1和Demo2,您需要打包我的解决方案来处理数组。

编辑:我意识到我创建了一个数组作为结果,但您可以很容易地完成此操作,而不是将所有数组附加到一个字符串中。

代码连接信息,它同时具有onedrive和存储blob,当前连接到存储blob,并最终输出到excel表:

{ "$connections": { "value": { "azureblob": { "connectionId": "/subscriptions/[GUID]/resourceGroups/StackOverFlow/providers/Microsoft.Web/connections/azureblob", "connectionName": "azureblob", "id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/azureblob" }, "excelonlinebusiness": { "connectionId": "/subscriptions/[GUID]/resourceGroups/StackOverFlow/providers/Microsoft.Web/connections/excelonlinebusiness", "connectionName": "excelonlinebusiness", "id": "/subscriptions/[GUID]/providers/Microsoft.Web/locations/westeurope/managedApis/excelonlinebusiness" }, "onedriveforbusiness": { "connectionId": "/subscriptions/[GUID]/resourceGroups/StackOverFlow/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]": "/stackoverflow/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" } } } }

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56759223

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档