Jayway JsonPath 内部数组的过滤表达式

6
我有一个以下格式的JSON文件。
{  
   "queryResponse":[  
      {  
         "id":"1",
         "name":"Parent1",
         "childList":[  
            {  
               "id":"11",
               "type":"A"
            },
            {  
               "id":"12",
               "type":"B"
            }
         ]
      },
      {  
         "id":"2",
         "name":"Parent2",
         "childList":[  
            {  
               "id":"21",
               "type":"B"
            },
            {  
               "id":"22",
               "type":"C"
            }
         ]
      }
   ]
}

使用 jayway JsonPath,我如何获取所有具有类型为“B”的子节点的父节点?
这些过滤表达式返回了一个空数组:
- 在索引中使用通配符,例如:$.queryResponse[?(@.childList[*].type=='B')] - 在过滤字段中使用深度扫描运算符,例如:$.queryResponse[?(@.childList..type=='B')]
唯一最接近我想要的过滤表达式是带有数组索引的表达式,例如:$.queryResponse[?(@.childList[0].type=='A')]。

你找到解决方案了吗? - user1555190
1个回答

0

使用containsin运算符

$.queryResponse[?(@.childList[*].type contains 'B')]

OR

$.queryResponse[?('B' in @.childList[*].type )]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接