在以下的 json 中,我需要得到的几个字段是:当 set.class.0 非空的时候,返回该 set 列表中的某些字段
{
    "code": 0,
    "msg": null,
    "data": {
        "set": [
            {
                "id": "1566",  "type": 1, 
                 "class": {  "0": [],"1": [ "460"],"2": ["460","460","461" ] },
            },
           {
                "id": "1788", "type": 1,
                "class": { "0": [ "461" ], "1": [], "2": [ "460" ]},
            },
            {
                "id": "1762","type": 1,
                "class": { "0": [],"1": [ "461" ], "2": [ "460" ],
            },
            {
                "id": "1790","type": 1, 
                "class": { "0": [ "460","461"], "1": [], "2": [] },
            },
            {
               "id": "1792","type": 2,
                "class": {"0": [ "460", "461"], "1": [],"2": []
                },
            },]
}}
既是当存在"0": [ "461" ] 与"0": [ "460", "461"] 等” 0“为非空内容时,取 set[0] 中的 id,type 与” 0"的属性值,在此例子中,则是得到 id=1788,type=1,"0"=461。我用 jsonpath 仅仅是实现了当 set.class.0 非空的时候,返回整个 set:
List<Object> list=JsonPath.read(string, "$.data.set[?(@.class.0.length()>0]");
得到的结果是
   {
                "id": "1788", "type": 1,
                "class": { "0": [ "461" ], "1": [], "2": [ "460" ]},
            },    
           {
                "id": "1790","type": 1, 
                "class": { "0": [ "460","461"], "1": [], "2": [] },
            },
          {
               "id": "1792","type": 2,
                "class": {"0": [ "460", "461"], "1": [],"2": []},
          }