简体   繁体   English

如何在 Azure 的 ADF V2 中的动态内容中转义 json?

[英]How to escape json in dynamic content in ADF V2 in Azure?

I'm calling Azure function and I'm building the request body using dynamic content.我正在调用 Azure function 并且正在使用动态内容构建请求正文。

This is how I build it:这就是我构建它的方式:

{
  "test": "Test1",
  "data": "@{activity('Upload SKU').output}"
}

I have problem with the "data" node.我对“数据”节点有问题。 @{activity('Upload SKU').output is a json string. @{activity('Upload SKU').output是 json 字符串。 So the dynamic content creates "mess".所以动态内容会造成“混乱”。 It doesn't escape it.它没有逃脱它。

It creates this:它创建了这个:

{
  "test": "Test1",
  "data": "{"a": "1"}"
}

How to escape @{activity('Upload SKU').output so that {"a": "1"} creates {\"a\": \"1\"} so that it can be treated as a string and not as a node under "data" .如何转义@{activity('Upload SKU').output以便{"a": "1"}创建{\"a\": \"1\"}以便可以将其视为字符串而不是作为"data"下的一个节点。

This is what I want to achieve:这就是我想要实现的目标:

{
  "test": "Test1",
  "data": "{\"a\": \"1\"}"
}

You could get some clues from my previous case: Error "BadRequest" when calling Azure Function in ADF .你可以从我之前的案例中得到一些线索: Error "BadRequest" when calling Azure Function in ADF

The solution is using @json() and @concat() in dynamic content.For you, the entire data may looks like:解决方案是在动态内容中使用@json()@concat() 。对您而言,整个data可能如下所示:

@json(concat('{"test": "Test1,"data":"',@{activity('Upload SKU').output,'"}'))

Just for summary:仅作总结:

It turns out there is error in ADF expression editor because when @Hooch put exactly the same expression directly into "body" field without using expression editor it works.事实证明,ADF 表达式编辑器中存在错误,因为当@Hooch 将完全相同的表达式直接放入“body”字段而不使用表达式编辑器时,它可以工作。

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

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