在逻辑应用中将 CSV 文件转换为数组
Convert CSV file as array in logic apps
我想在逻辑应用程序中将 CSV 文件读取为数组。我没有找到任何与之相关的文件。对此的任何帮助将不胜感激。谢谢!
根据您的问题,我们可以尝试以下两种不同的输出方式。
读取每个 OBJECT CSV 文件作为数组 OBJECT:
我们可以使用 split 并通过添加 'Initialise Variable' 连接器将 compose
连接器的输出添加到数组中,为了将每个单词转换为数组变量,我们需要在另一个 for each
中添加 for each
连接器] 连接器迭代 CSV 文件内的项目,然后在具有 split(item(),',')
表达式的内部 for each
连接器内使用拆分变量。
以数组形式读取 CSV 文件中的每一行:
考虑到 CSV 文件中的 headers,我们可以使用 Plumsail 的 Parse CSV 连接器将每个 CSV 行转换为数组。
这里有截图供大家参考
compose
连接器中的表达式
split(body('Get_blob_content_(V2)'),'\n')
For each 2
连接器中的表达式
split(item(),',')
注意:确保您转到代码视图并更改拆分中的表达式
split(body('Get_blob_content_(V2)'),'\n')
到 split(body('Get_blob_content_(V2)'),'\n')
因为当我们为此编写表达式时,它首先将 '\n' 作为字符串并向表达式添加另一个 ""。
这是我的逻辑应用程序的代码视图
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@split(body('Get_blob_content_(V2)'),'\n')",
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_2": {
"inputs": "@variables('array1')",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array1",
"value": "@items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "@split(item(),',')",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "@outputs('Compose')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob_1']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2": "/container24/data-article.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array1",
"type": "array",
"value": "@outputs('Compose')"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_CSV": {
"inputs": {
"body": {
"content": "@{base64(body('Get_blob_content_(V2)'))}",
"headers": "url,user_id,token_id,username,password"
},
"host": {
"connection": {
"name": "@parameters('$connections')['plumsail']['connectionId']"
}
},
"method": "post",
"path": "/flow/v1/Documents/jobs/ParseCsv"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob_1": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups<Your resourec group >/providers/Microsoft.Web/connections/azureblob-1",
"connectionName": "azureblob-1",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
},
"plumsail": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups/<Your resourec group >/providers/Microsoft.Web/connections/plumsail",
"connectionName": "plumsail",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/plumsail"
}
}
}
}
}
参考资料:
Convert CSV elements into a single Array using Azure Logic Apps - Stack Overflow
我想在逻辑应用程序中将 CSV 文件读取为数组。我没有找到任何与之相关的文件。对此的任何帮助将不胜感激。谢谢!
根据您的问题,我们可以尝试以下两种不同的输出方式。
读取每个 OBJECT CSV 文件作为数组 OBJECT:
我们可以使用 split 并通过添加 'Initialise Variable' 连接器将 compose
连接器的输出添加到数组中,为了将每个单词转换为数组变量,我们需要在另一个 for each
中添加 for each
连接器] 连接器迭代 CSV 文件内的项目,然后在具有 split(item(),',')
表达式的内部 for each
连接器内使用拆分变量。
以数组形式读取 CSV 文件中的每一行: 考虑到 CSV 文件中的 headers,我们可以使用 Plumsail 的 Parse CSV 连接器将每个 CSV 行转换为数组。
这里有截图供大家参考
compose
连接器中的表达式split(body('Get_blob_content_(V2)'),'\n')
For each 2
连接器中的表达式split(item(),',')
注意:确保您转到代码视图并更改拆分中的表达式
split(body('Get_blob_content_(V2)'),'\n')
到 split(body('Get_blob_content_(V2)'),'\n')
因为当我们为此编写表达式时,它首先将 '\n' 作为字符串并向表达式添加另一个 ""。
这是我的逻辑应用程序的代码视图
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Compose": {
"inputs": "@split(body('Get_blob_content_(V2)'),'\n')",
"runAfter": {
"Get_blob_content_(V2)": [
"Succeeded"
]
},
"type": "Compose"
},
"Compose_2": {
"inputs": "@variables('array1')",
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "Compose"
},
"For_each": {
"actions": {
"For_each_2": {
"actions": {
"Append_to_array_variable": {
"inputs": {
"name": "array1",
"value": "@items('For_each_2')"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "@split(item(),',')",
"runAfter": {},
"type": "Foreach"
}
},
"foreach": "@outputs('Compose')",
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Get_blob_content_(V2)": {
"inputs": {
"host": {
"connection": {
"name": "@parameters('$connections')['azureblob_1']['connectionId']"
}
},
"method": "get",
"path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files/@{encodeURIComponent(encodeURIComponent('JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2'))}/content",
"queries": {
"inferContentType": true
}
},
"metadata": {
"JTJmY29udGFpbmVyMjQlMmZkYXRhLWFydGljbGUuY3N2": "/container24/data-article.csv"
},
"runAfter": {},
"type": "ApiConnection"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "array1",
"type": "array",
"value": "@outputs('Compose')"
}
]
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Parse_CSV": {
"inputs": {
"body": {
"content": "@{base64(body('Get_blob_content_(V2)'))}",
"headers": "url,user_id,token_id,username,password"
},
"host": {
"connection": {
"name": "@parameters('$connections')['plumsail']['connectionId']"
}
},
"method": "post",
"path": "/flow/v1/Documents/jobs/ParseCsv"
},
"runAfter": {
"Compose": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"azureblob_1": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups<Your resourec group >/providers/Microsoft.Web/connections/azureblob-1",
"connectionName": "azureblob-1",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/azureblob"
},
"plumsail": {
"connectionId": "/subscriptions/<Your subscription>/resourceGroups/<Your resourec group >/providers/Microsoft.Web/connections/plumsail",
"connectionName": "plumsail",
"id": "/subscriptions/<Your subscription>/providers/Microsoft.Web/locations/northcentralus/managedApis/plumsail"
}
}
}
}
}
参考资料: Convert CSV elements into a single Array using Azure Logic Apps - Stack Overflow