0

我想在逻辑应用程序中将 CSV 文件作为数组读取。我没有找到任何相关的文件。对此的任何帮助将不胜感激。谢谢!

4

1 回答 1

2

根据您的问题,这里有一些我们可以尝试以下两种不同输出的方法。

将每个对象 CSV 文件读取为数组对象: 我们可以使用拆分并将compose连接器的输出添加到数组中,方法是添加“初始化变量”连接器,并将每个单词转换为数组变量,我们需要for each在另一个for each连接器中添加连接器以迭代里面的项目然后 CSV 文件在for each具有split(item(),',')表达式的内部连接器内带有一个拆分变量。

将 CSV 文件中的每一行读取为一个数组: 我们可以使用 Plumsail 的 Parse CSV 连接器将每个 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"
                }
            }
        }
    }
}

参考: 使用 Azure 逻辑应用将 CSV 元素转换为单个数组 - 代码日志

于 2021-11-17T09:43:58.100 回答