卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章35640本站已运行398

Go Kazaam 转换返回意外结果

go kazaam 转换返回意外结果

php小编柚子近日发现,一款新的转换工具Go Kazaam在用户使用过程中出现了一些意外结果。该工具原本被设计用于帮助开发者快速转换代码,提高开发效率。然而,一些用户反馈称,在使用过程中出现了一些意料之外的问题。这引起了开发者和用户的关注,我们将在本文中对该问题进行探讨,并给出解决方案。

问题内容

我使用 kazaam 模块来定义 json 转换。 https://github.com/qntfy/kazaam

这些是我的规则:

"rules": [
        {
            "operation": "shift",
            "spec": {
                "Shift": "instruction.context.example1"
            }
        },
        {
            "operation": "concat",
            "spec": {
                "sources": [
                    {
                        "path": "instruction.context.example1"
                    },
                    {
                        "path": "instruction.context.example2"
                    }
                ],
                "targetPath": "Concat",
                "delim": "_"
            }
        },
        {
            "operation": "coalesce",
            "spec": {
                "Coalesce": [
                    "instruction.context.example3[0].id"
                ]
            }
        }
    ]

应用于此 json:

{
    "instruction": {
        "context": {
            "example1": "example1 value",
            "example2": "example2 value",
            "example3": [
                {
                    "id": "example3_1_value"
                },
                {
                    "id": "example3_2_value"
                },
                {
                    "id": "example3_3_value"
                }
            ]
        }
    }
}

结果是这样的:

{
    "Shift": "example1 value",
    "Concat": "null_null"
}

因此第一个操作有效,第二个操作返回 null_null,而第三个操作则不会出现。

解决方法

这些规则会依次应用。第一个规则产生的结果将作为第二个规则的输入,依此类推,它们是链接在一起的。因此,您首先转换会产生一个对象:

{
  "Shift": "example1 value"
}

当上述内容作为第二个操作的输入时 - 您将获得 null 值,因为您所引用的字段 - 不存在。
您可以尝试将第一条规则更改为:

{
            "operation": "shift",
            "spec": {
                "Shift": "instruction.context.example1",
                "instruction.context.example1": "instruction.context.example1",
                "instruction.context.example2": "instruction.context.example2"
            }
        },

看看它的效果。

卓越飞翔博客
上一篇: GLSL 片段着色器无法编译且没有任何消息
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏