Azure 数据工厂 - 如何 trim 双引号并转换为字符串?

Azure Data Factory - how can I trim double quotes and convert to a string?

我在 ADF 中有一个通往 REST API 端点的管道,其中 returns 一个用双引号 (") 括起来的字符串。看起来像这样:"xyz123fj==" 我什么我试图做的是将字符串值存储在一个名为 AuthKey 的变量中。最初我只是“按原样”存储它,但管道失败并出现以下错误:The variable 'AuthKey' of type 'String' cannot be initialized or updated with value of type 'Object'. The variable 'AuthKey' only supports values of types 'String'.

所以我自然而然地想我会尝试转换为这样的字符串:string(@activity('Get Token').output) 这实际上允许成功存储变量,但下一步失败并显示消息:Error calling the endpoint 'https://<xxxxxx.com/APIendpoint>'. Response status code: ''. More details:Exception message: 'The format of value 'string(@activity('Get Token').output)' is invalid.'. No response from the endpoint. Possible causes: network connectivity, DNS failure, server certificate validation or timeout.

我怀疑这意味着它实际上并没有存储原始的 'xyz123fj==' 字符串,而是将未评估的函数本身存储为一个字符串(因此它存储了 string(@activity('Get Token').output) ,当发送到API.

我也尝试了 @string(activity('Get Token').output),结果出现了稍微不同的错误消息:More details:Exception message: 'The format of value '{"Response":"\"xyz123fj==\"","ADFWebActivityResponseHeaders":{"Pragma":"no-cache","Strict-Transport-Security":"max-age=31536000","X-Absorb-Correlation-Id":"c937fab2-3e6c-4d92-8b28-5375fb2d5721","X-Content-Type-Options":"nosniff","X-Frame-Options":"SAMEORIGIN","X-LMS-Server":"USE1-PRD-WEB-A3","X-Response-For":"/api/Rest/v1/Authenticate","X-XSS-Protection":"1; mode=block","Connection":"keep-alive","Cache-Control":"no-cache","Date":"Mon, 03 May 2021 15:53:01 GMT","Content-Length":"178","Content-Type":"application/json; charset=utf-8","Expires":"-1"},"effectiveIntegrationRuntime":"DefaultIntegrationRuntime (East US)","executionDuration":0,"durationInQueue":{"integrationRuntimeQueue":0},"billingReference":{"activityType":"ExternalActivity","billableDuration":[{"meterType":"AzureIR","duration":0.016666666666666666,"unit":"Hours"}]}}' is invalid.'. No response from the endpoint.

在最后一个示例中,使用变量的步骤似乎正在从“设置变量”activity 接收完整的输出对象,而不是预期的简单字符串。任何关于我在这里做错的见解将不胜感激。

我也试过只去掉单引号(所以没有字符串转换函数),但也无法让它工作。我想做的就是自己存储这个字符串:(

你应该可以在变量的赋值中写 @activity('Get Token').output.Response

您的 Response 值似乎包含在双引号中,因此您可能不得不这样做以去除引号:@replace(activity('Get Token').output.Response,'\"','')

activity('Get Token').output is type object - 这就是第一个错误发生的原因(不能将其分配给字符串变量)。

在第二种情况下,您的表达式必须以 @ 开头才能被这样解释。

在最后一种情况下,您将从 REST activity(您可以在监视器中看到)作为令牌发送整个输出,它具有端点不期望的格式。

你应该使用 @replace(activity('Get Token').output.Response,'"','') 表达式,反斜杠是 ADF 中的转义字符。