ADF - 从 JSON 数组中获取值以将其用作变量

问题描述 投票:0回答:1

我想做什么?

第一步:我想从 JSON 文件中获取用户 (ID) 的所有值,并将它们放在一个列表中。

第二步:在变量中使用 ID,如 https://microsoft.com/API/threads_createdby="&ID&" 检索由 User1、User2、User3 等创建的所有线程。

现在我正在使用查找(数据集)导入 JSON 文件,如下所示:

{ "count": 1, "value": [ { "result": [ { "user": { "display_value": "User1", "link": "https://microsoft.com", "value": "4356yrtge43t5gre" } }, { "user": { "display_value": "User2", "link": "https://microsoft.com", "value": "fdgtrh5t4rewfr54" } }, { "user": { "display_value": "User3", "link": "https://microsoft.com", "value": "rgethyj7u6y5terf" } } ] } ], "effectiveIntegrationRuntime": "server343", "billingReference": { "activityType": "PipelineActivity", "billableDuration": [ { "meterType": "SelfhostedIR", "duration": 0.016666666666666666, "unit": "Hours" } ] }, "durationInQueue": { "integrationRuntimeQueue": 1 } }

下一步是使用附加变量 (@activity('JSONImport').output.value & @item().result 的 Foreach,我可以看到所有 ID 以及此错误消息

of type 'Array' cannot be appended to the variable 'Value' of type 'Array'. The action type 'AppendToArrayVariable' only supports values of types 'Float, Integer, String, Boolean, Object'.

使用@item().result[0].user.value 我看到了这个:

{ "variableName": "Value", "value": "4356yrtge43t5gre" }

我做错了什么?

致以诚挚的问候

azure-data-factory
1个回答
0
投票

当我尝试使用您在 Foreach 中给出的相同表达式并追加时,我最终遇到了同样的错误。

enter image description here

发生上述错误是因为当您查看查找活动输出数组值是一个数组并且

result
也是一个数组。该错误指出不支持将数组附加到数组。所以,错误来了,因为你试图将一个数组(
result
)附加到另一个数组。

第二步:在变量中使用 ID,如 https://microsoft.com/API/threads_createdby="&ID&" 检索由 User1、User2、User3 等创建的所有线程。

result
数组位于查找输出数组的
0th
索引处。因此,要实现您的要求,请将结果数组提供给 Foreach 并在其中使用附加活动。

@activity('Lookup1').output.value[0].result

另外,为了示例,我给出了以下动态内容(以演示访问

value
键)。

https://microsoft.com/API/thread_createdby=@{item().user.value}

enter image description here

结果:

enter image description here

如果您想将结果数组存储在数组变量中,您可以直接在设置变量活动中使用相同的

@activity('Lookup1').output.value[0].result
并根据您的要求使用。

© www.soinside.com 2019 - 2024. All rights reserved.