Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JSONPath] 用“$..[?(@.price < 10)]”获取JSONArray的值报illeal jsonpath syntax #3629

Closed
pengyongjun opened this issue Jan 27, 2021 · 0 comments
Assignees
Milestone

Comments

@pengyongjun
Copy link

用 JSONPath.extract(text1, "$..[?(@.price < 10)]").toString()); 获取JSONArray的值时,报:
Exception in thread "main" com.alibaba.fastjson.JSONPathException: illeal jsonpath syntax. $..[?(@.price < 10)]

        String text1 = "[\n" +
                "    {\n" +
                "        \"author\": \"Nigel Rees\",\n" +
                "        \"category\": \"reference\",\n" +
                "        \"price\": 8.95,\n" +
                "        \"title\": \"Sayings of the Century\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"author\": \"Evelyn Waugh\",\n" +
                "        \"category\": \"fiction\",\n" +
                "        \"price\": 12.99,\n" +
                "        \"title\": \"Sword of Honour\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"author\": \"Herman Melville\",\n" +
                "        \"category\": \"fiction\",\n" +
                "        \"isbn\": \"0-553-21311-3\",\n" +
                "        \"price\": 8.99,\n" +
                "        \"title\": \"Moby Dick\"\n" +
                "    },\n" +
                "    {\n" +
                "        \"author\": \"J. R. R. Tolkien\",\n" +
                "        \"category\": \"fiction\",\n" +
                "        \"isbn\": \"0-395-19395-8\",\n" +
                "        \"price\": 22.99,\n" +
                "        \"title\": \"The Lord of the Rings\"\n" +
                "    }\n" +
                "]";

        logger.info(JSONPath.extract(text1, "$..[?(@.price < 10)]").toString());

同样的方式,在http://jsonpath.herokuapp.com/ 是可以的

[
    {
        "author": "Nigel Rees",
        "category": "reference",
        "price": 8.95,
        "title": "Sayings of the Century"
    },
    {
        "author": "Evelyn Waugh",
        "category": "fiction",
        "price": 12.99,
        "title": "Sword of Honour"
    },
    {
        "author": "Herman Melville",
        "category": "fiction",
        "isbn": "0-553-21311-3",
        "price": 8.99,
        "title": "Moby Dick"
    },
    {
        "author": "J. R. R. Tolkien",
        "category": "fiction",
        "isbn": "0-395-19395-8",
        "price": 22.99,
        "title": "The Lord of the Rings"
    }
]
@wenshao wenshao self-assigned this Jan 27, 2021
@wenshao wenshao added this to the 1.2.76 milestone Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants