假设我有此数据示例:-
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"color": "red",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"color": "blue",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
如果我查找JsonPath $ .store..isbn 我回来了:-
[
"0-553-21311-3",
"0-395-19395-8"
]
我想要的是:-
[
null,
null,
"0-553-21311-3",
"0-395-19395-8"
]
有人可以说出在JsonPath中是否可行吗?如果没有,还有其他选择吗?
答案 0 :(得分:0)
您可以尝试比较结果长度和数据长度,然后将所需的null量压入数组的开头。
答案 1 :(得分:0)
使用Configuration即可实现。
需要在配置中设置Files: export
选项,如果节点不在其中,它将返回null
完整示例为:
Protect File
输出:
Option.DEFAULT_PATH_LEAF_TO_NULL