json - json的颠簸转换-如何为空值添加移位操作
问题描述
我有三个场景:
场景 1:应何时"testInt" == 10
将 then"isTrue"
设置为false
和"testInt"
to0
和"testString"
as it is。
输入
{
"testString" :"testValue",
"testInt": 10,
"isTrue": true
}
预期产出
{
"testString" :"testValue",
"testInt": 0,
"isTrue": false
}
场景 2:什么时候应该删除 then 而其他的应该被删除"testInt" == null
。"testInt"
输入
{
"testString" :"testValue",
"testInt": null,
"isTrue": true
}
预期产出
{
"testString" :"testValue",
"isTrue": true
}
场景 3:当"testInt" != 10
(also not null
) 然后没有变化。
输入
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
预期产出
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
如果有人建议我如何通过颠簸操作来实现这些,那将会很有帮助。
解决方案
您可以将此类shift
操作与default
操作一起定义,以便能够通过转换来处理null
案例"null"
null
[{
"operation": "default",
"spec": {
"testInt": "null"
}
},{
"operation": "shift",
"spec": {
"testString": "testString",
"testInt": {
"10": {
"#0": "testInt"
},
"null": null,
"*": {
"@(2,testInt)": "testInt"
}
},
"isTrue": {
"@(2,testInt)": {
"10": {
"#false": "isTrue"
},
"*": {
"@(3,isTrue)": "isTrue"
}
}
}
}
}]
@(integer,key)
例如"@(2,testInt)"
或表示"@(3,isTrue)"
要开始搜索作为第二个参数呈现的所需键的级别。"spec": {
这可以通过在除了 this first {
within之后计算打开的花括号来计算"spec": {
。
推荐阅读
- android - 约束视图问题
- python - 如何在python中使用函数和循环调用变量
- javascript - 如何将 API JSON 响应参数传递给材质 ui 表
- google-app-engine - 使用 requirements.txt 的 Google App Engine 标准 Python 3 上的 Ta-lib 包
- r - 如何添加缺失的美学:标签到 geom_label()
- sql-server - 如果值增加 > 5,则创建警报 - SQL Server
- c++ - 问题:了解项目结构
- sql - oracle sql触发器计算
- ios - 加载 HTML 内容时 TableView 出现故障
- mysql - 删除具有重复列的行