我想使用Jolt处理器实现JSON转换 我的json中有null的字段,我想删除所有这些字段
{............... " myValue":345, " colorValue":null," degreeDayValue":null," depthValue":null," distanceValue":null ....... ....}
只保留myValue字段......
我可以通过移除操作来实现这一点吗? 最好的祝福 菲尔
答案 0 :(得分:1)
这是可能的,只是不容易或直截了当。需要两个步骤。
规格
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton = (Button)findViewById(R.id.button);
mEdit = (EditText)findViewById(R.id.edittext);
mButton.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
Log.v("EditText", mEdit.getText().toString());
}
});}
可生产
[
{
"operation": "default",
"spec": {
// for all keys that have a null value
// replace that null value with a placeholder
"*": "PANTS"
}
},
{
"operation": "shift",
"spec": {
// match all keys
"*": {
// if the value of say "colorValue" is PANTS
// then, match but do nothing.
"PANTS": null,
// otherwise, any other values are ok
"*": {
// "recreate" the key and the non-PANTS value
// Write the value from 2 levels up the tree the "@1"
// to the key from 3 levels up the tree => "&2".
"@1": "&2"
}
}
}
}
]
答案 1 :(得分:0)
要从内部数组中删除null,请在末尾使用以下代码
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=recursivelySquashNulls"
}
}