Skip to content

[QUESTION]复杂筛选问题 #1410

@microver

Description

@microver

一个JSONObject对象,递归属性,查询所有dictTypeId节点为”city“,dictId节点为“101”的节点(dictTypeId 和dictId节点可能在任意层级),Java语言查询方式如下:
Object childArr=JsonUtil.read(jsonArr, "$.[?( @.dictTypeId =='city' && @.dictId =='101' )]");
查询结果childArr对象为空(非null)。

请问,jsonpath该如何设置?

用JSONPath在线工具查询,可以得到结果,信息如下:
工具网址:https://www.jsonpath.cn/
JSONPath语法输入内容:$.[?( @.dictTypeId =='city' && @.dictId =='101' )]
输入:JSONObject对象字符串
验证结果为:

[
  {
    "dictId": "101",
    "dictName": "Nanjing",
    "dictTypeId": "city",
    "level": 1,
    "parentId": "1",
    "rank": 3,
    "seqno": ".CN.1.101.",
    "sortno": 1,
    "status": 1
  }
]

JSONObject对象如下:

[
    {
        "dictId": "CN",
        "dictName": "China",
        "dictTypeId": "country",
        "level": 1,
        "rank": 1,
        "seqno": ".CN.",
        "sortno": 1,
        "status": 1,
        "children": [
            {
                "dictId": "1",
                "dictName": "Jiangsu",
                "dictTypeId": "province",
                "level": 1,
                "parentId": "CN",
                "rank": 2,
                "seqno": ".CN.1.",
                "sortno": 1,
                "status": 1,
                "children": [
                    {
                        "dictId": "101",
                        "dictName": "Nanjing",
                        "dictTypeId": "city",
                        "level": 1,
                        "parentId": "1",
                        "rank": 3,
                        "seqno": ".CN.1.101.",
                        "sortno": 1,
                        "status": 1
                    },
                    {
                        "dictId": "102",
                        "dictName": "Changzhou",
                        "dictTypeId": "city",
                        "level": 1,
                        "parentId": "1",
                        "rank": 3,
                        "seqno": ".CN.1.102.",
                        "sortno": 2,
                        "status": 1
                    }
                ]
            },
            {
                "dictId": "2",
                "dictName": "Guangdong",
                "dictTypeId": "province",
                "level": 1,
                "parentId": "CN",
                "rank": 2,
                "seqno": ".CN.2.",
                "sortno": 2,
                "status": 1,
                "children": [
                    {
                        "dictId": "201",
                        "dictName": "Guangzhou",
                        "dictTypeId": "city",
                        "level": 1,
                        "parentId": "2",
                        "rank": 3,
                        "seqno": ".CN.2.201.",
                        "sortno": 1,
                        "status": 1
                    }
                ]
            }
        ]
    }
]

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions