液体中的空间处理程序不起作用

发布于 2025-01-28 18:07:11 字数 1210 浏览 2 评论 0原文

我无法弄清楚如何从字符串的开始和结尾处删除空格。
我的响应主体是:

{
    "value": [
        {
            "nomeUnidadeOperacional": " ",
            "nomeCaixaPostalComunitaria": " ",
            "nroCaixaPostal": " ",
            "enderecoCaixapostal": " "
        }
    ]
}

我尝试使用“ | split”和“ {% - 分配item = body.value [0] - %}”作为液体文档说明“空间控制”。

我的固定体:

<set-body template="liquid">
    {
        "Endereco": {       
            {% assign item = body.value[0] %}
            "caixaPostal": {
                "nome": "{{item.nomeCaixaPostalComunitaria | strip }}",
                "numero": "{{item.nroCaixaPostal | strip }}",
                "endereco": "{{item.enderecoCaixapostal | strip }}"
            }
        }
    }
</set-body>

我得到的:

{
    "Endereco": {
        "caixaPostal": {
            "nome": " ",
            "numero": " ",
            "endereco": " "
        }
    }
}

我期望的是:

{
    "Endereco": {
        "caixaPostal": {
            "nome": "",
            "numero": "",
            "endereco": ""
        }
    }
}

确保可以使用IF测试内容是否为“”并在此之后替换,但是我可以拥有1个以上的空间,并且此选项并不优雅。

I cannot figure out how to remove whitespaces from the start and end of my strings.
My response body is:

{
    "value": [
        {
            "nomeUnidadeOperacional": " ",
            "nomeCaixaPostalComunitaria": " ",
            "nroCaixaPostal": " ",
            "enderecoCaixapostal": " "
        }
    ]
}

I tried using "| split" and "{%- assign item = body.value[0] -%}" as the documentation for liquid explain "whitespace control".

My set-body:

<set-body template="liquid">
    {
        "Endereco": {       
            {% assign item = body.value[0] %}
            "caixaPostal": {
                "nome": "{{item.nomeCaixaPostalComunitaria | strip }}",
                "numero": "{{item.nroCaixaPostal | strip }}",
                "endereco": "{{item.enderecoCaixapostal | strip }}"
            }
        }
    }
</set-body>

What I'm getting:

{
    "Endereco": {
        "caixaPostal": {
            "nome": " ",
            "numero": " ",
            "endereco": " "
        }
    }
}

What I expected:

{
    "Endereco": {
        "caixaPostal": {
            "nome": "",
            "numero": "",
            "endereco": ""
        }
    }
}

Sure i could use a if to test if the content is " " and replace it after, but i could have more than 1 whitespace and this option isn't elegant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2025-02-04 18:07:11

在API管理上,您需要编写大写的过滤器。

"nome": "{{item.nomeCaixaPostalComunitaria | Strip }}",

On API Management you need to write the Filter Capitalized.

"nome": "{{item.nomeCaixaPostalComunitaria | Strip }}",
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文