如果父元素既可以是 JSONArray 也可以是 JSONObject,我就不得不麻烦地检索值。为此,我使用 Deepcopy 语法来检索它。如果内部数组中也存在子属性,现在的问题是获得额外的值。
例如:JpathExpression:
$.store..book..innerBook..category
结果是:
[
"innerReference1",
"innerBook1Ref1",
"innerReference2"
]
示例 1 预期结果是:
[
"innerReference1",
"innerReference2"
]
示例 1:
{
"store": {
"book": [
{
"innerBook": [
{
"category": "innerReference1",
"author": "Nigel Rees",
"innerBook1": [
{
"category": "innerBook1Ref1"
}
]
},
{
"category": "innerReference2",
"author": "Nigel Rees"
}
]
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
示例 2:
{
"store": {
"book": [
{
"innerBook":
{
"category": "innerReference1",
"author": "Nigel Rees",
"innerBook1": [
{
"category": "innerBook1Ref1"
}
]
}
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
示例 2 预期结果是:
[
"innerReference1"
]