0

当我的 Liquid 模板在数组对象中迭代时出现问题。我想将一个输入 json 转换成另一个输出 json。

这是我的液体模板:

{% assign clientList = Clients.value %}

{
    "value": [
        {% for client in clientList %}
            {
                "ACCOUNTNUM": "{{client.ACCOUNTNUM}}",
                "EMAIL": "{{client.EMAIL}}",
                "NAME": "{{client.NAME}}",
                "PHONE": "{{client.PHONE}}",
                "VATNUM": "{{client.VATNUM}}",
                "RECID": "{{client.RECID}}",
                "CANALID": "{{client.CANALID}}",
                "CANALDESC": "{{client.CANALDESC}}"
            }
                {% if forloop.Last == false %}
                , 
                {% endif %}
            {% endfor %}
    ]
}

这是一个输入 json 示例:

{
   "Clients":{
      "value":[
         {
            "@odata.etag":"",
            "ItemInternalId":"3a93f2aa-dd77-4297-88c4-13241343321",
            "ACCOUNTNUM":"01",
            "EMAIL":"info@example.es",
            "LANGUAGEID":"es",
            "NAME":"Lili S.A.",
            "PHONE":"943444666",
            "VATNUM":"A01",
            "DATAAREAID":"tr2",
            "RECID":1412,
            "DATAAREAID_x0023_2":"tr2",
            "DATAAREAID_x0023_3":"tr2",
            "CANALID":"C0010",
            "CANALDESC":"Group gg"
         },
         {
            "@odata.etag":"",
            "ItemInternalId":"3a23f2aa-dd77-4297-88c4-13241343321",
            "ACCOUNTNUM":"02",
            "EMAIL":"info@example.es",
            "LANGUAGEID":"es",
            "NAME":"Lili2 S.A.",
            "PHONE":"943444656",
            "VATNUM":"A02",
            "DATAAREAID":"tr2",
            "RECID":1412,
            "DATAAREAID_x0023_2":"tr2",
            "DATAAREAID_x0023_3":"tr2",
            "CANALID":"C0011",
            "CANALDESC":"Group2 gg"
         }
      ]
   }
}

当我启动我的逻辑应用程序时,我收到了这个错误:

{\"StatusCode\":400,\"ErrorCode\":18,\"Details\":null,\"Message\":\"将转换后的值转换为 JSON 时出错。转换后的值不是有效 JSON。'解析值后遇到意外字符::. 路径'print1',第 5 行,位置 11。'\"

4

1 回答 1

1

根据一些测试,它应该是由您的液体中如下所示的部分引起的:

{% if forloop.Last == false %}
, 
{% endif %}

我删除了这部分并且液体贴图工作正常,在这里我将我的液体贴图贴在下面供您参考:

{
    "value": [
        {% for client in content.Clients.value %}
            {
                "ACCOUNTNUM": "{{client.ACCOUNTNUM}}",
                "EMAIL": "{{client.EMAIL}}",
                "NAME": "{{client.NAME}}",
                "PHONE": "{{client.PHONE}}",
                "VATNUM": "{{client.VATNUM}}",
                "RECID": "{{client.RECID}}",
                "CANALID": "{{client.CANALID}}",
                "CANALDESC": "{{client.CANALDESC}}"
            }, 
        {% endfor %}
    ]
}

不要担心最后一个“,”,因为“将 JSON 转换为 JSON”操作会处理它。在“将 JSON 转换为 JSON”操作的输出中,它不会在 json 末尾显示额外的“,”。

于 2019-12-04T13:41:37.677 回答