简体   繁体   English

集合中的引号和特殊字符问题以及 ADF 中的 append 变量

[英]Quotes and special character issue in set and append variable in ADF

I'm trying to prepare a variable value using set and append variable that needs to be passed to the request body of the copy activity to fetch the data from API.我正在尝试使用 set 和 append 变量准备一个变量值,该变量需要传递到复制活动的请求正文以从 API 获取数据。 I need to do lookup of 100 values from DB at a time and form a array of values but " (quote) value is getting appended in the starting, end and in between of values due to which the copy activity is failing. I'm trying for the first two values as of now. "[\"{\\\"RIC\\\":{\\\"Value\\\":\\\"FHN.N\\\"}}\",\"{\\\"RIC\\\":{\\\"Value\\\":\\\"0142.HK\\\"}}\"]" this is the final variable output that I'm getting, I've removed the additional \ (slashes) using @replace(string(variables('RIC')),'','') and the output was - "[\"{\"RIC\":{\"Value\":\"FHN.N\"}}\",\"{\"RIC\":{\"Value\":\"0142.HK\"}}\"]" due to the " quotes in between the two RIC values and in between }] in the starting and at the end it's failing.我需要一次从数据库中查找 100 个值并形成一个值数组,但是由于复制活动失败,“(引用)值被附加在值的开始、结束和中间。我是目前正在尝试前两个值。 "[\"{\\\"RIC\\\":{\\\"Value\\\":\\\"FHN.N\\\"}}\",\"{\\\"RIC\\\":{\\\"Value\\\":\\\"0142.HK\\\"}}\"]"这是最终的变量 output我明白了,我已经使用 @replace(string(variables('RIC')),'','') 删除了额外的 \ (斜杠),并且 output 是 - "[\"{\"RIC\":{\"Value\":\"FHN.N\"}}\",\"{\"RIC\":{\"Value\":\"0142.HK\"}}\"]"到期到 " 两个 RIC 值之间和 }] 之间的引号,在开始和结束时它失败了。 If I can get the output as "[{"RIC":{"Value":"FHN.N"}},{"RIC":{"Value":"0142.HK"}}]" it would solve the issue as I tried passing this manually.如果我能得到 output 作为 "[{"RIC":{"Value":"FHN.N"}},{"RIC":{"Value":"0142.HK"}}]" 它将解决当我尝试手动传递时出现问题。

Request body passed in copy activity - "{"GetSignificantDevelopments_Request_1":{"FindRequest":{"CompanyIdentifiers_typehint":["CompanyIdentifiers","CompanyIdentifiers"],"CompanyIdentifiers":["{"RIC":{"Value":"FHN.N"}}","{"RIC":{"Value":"0142.HK"}}"],"StartDate": "2021-01-05T00:00:00","EndDate": "2021-01-06T00:00:00","Significance": "1 2 3","MaxNumberOfItems": 100}}}", - this is failing在复制活动中传递的请求正文 - "{"GetSignificantDevelopments_Request_1":{"FindRequest":{"CompanyIdentifiers_typehint":["CompanyIdentifiers","CompanyIdentifiers"],"CompanyIdentifiers":["{"RIC":{"Value":" FHN.N"}}","{"RIC":{"Value":"0142.HK"}}"],"StartDate":"2021-01-05T00:00:00","EndDate":" 2021-01-06T00:00:00","Significance":"1 2 3","MaxNumberOfItems": 100}}}",-这是失败的

manually tried successful request body - "{"GetSignificantDevelopments_Request_1":{"FindRequest":{"CompanyIdentifiers_typehint":["CompanyIdentifiers","CompanyIdentifiers"],"CompanyIdentifiers":[{"RIC":{"Value":"FHN.N"}},{"RIC":{"Value":"0142.HK"}}],"StartDate": "2021-01-05T00:00:00","EndDate": "2021-01-06T00:00:00","Significance": "1 2 3","MaxNumberOfItems": 100}}}",手动尝试成功的请求正文 - "{"GetSignificantDevelopments_Request_1":{"FindRequest":{"CompanyIdentifiers_typehint":["CompanyIdentifiers","CompanyIdentifiers"],"CompanyIdentifiers":[{"RIC":{"Value":"FHN. N"}},{"RIC":{"Value":"0142.HK"}}],"StartDate":"2021-01-05T00:00:00","EndDate":"2021-01-06T00 :00:00","意义":"1 2 3","MaxNumberOfItems": 100}}}",

The other way would be to use Replace function to replace all unwanted characters from the variable like: @replace(string(variables('RIC')),'','') where \ is just one of the characters.另一种方法是使用 Replace function 替换变量中所有不需要的字符,例如:@replace(string(variables('RIC')),'','') 其中\只是其中一个字符。 You can keep on concatenating replace functions to replace other characters and achieve your output.您可以继续连接替换功能以替换其他字符并实现您的 output。 Hope this would be helpful:)希望这会有所帮助:)

It's difficult to transform "[\"{\"RIC\":{\"Value\":\"FHN.N\"}}\",\"{\"RIC\":{\"Value\":\"0142.HK\"}}\"]" .很难转换"[\"{\"RIC\":{\"Value\":\"FHN.N\"}}\",\"{\"RIC\":{\"Value\":\"0142.HK\"}}\"]" Because it's not a valid JSON Data.因为它不是有效的 JSON 数据。 You can try to use substring function to get two JSON object {"RIC":{"Value":"FHN.N"}} and {"RIC":{"Value":"0142.HK"}} . You can try to use substring function to get two JSON object {"RIC":{"Value":"FHN.N"}} and {"RIC":{"Value":"0142.HK"}} . And then use concat function to compose your request body like this:然后使用concat function 组成您的请求正文,如下所示:

@{concat('{"GetSignificantDevelopments_Request_1":{"FindRequest":{"CompanyIdentifiers_typehint":["CompanyIdentifiers","CompanyIdentifiers"],"CompanyIdentifiers":[',json(substring(variables('RIC'),2,24)),',',json(substring(variables('RIC'),30,26)),'],"StartDate": "2021-01-05T00:00:00","EndDate": "2021-01-06T00:00:00","Significance": "1 2 3","MaxNumberOfItems": 100}}}')}

I used the replace function and got the desired output.我使用了替换 function 并得到了所需的 output。

@replace(replace(replace(replace(string(variables('RIC')),'\',''),'["{','[{'),'}"]','}]'),'}","{','},{')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM