使用JSONPath从单个对象检索json数据

时间:2016-11-05 03:17:40

标签: json jsonpath

鉴于下面的JSON:

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century"
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3"
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": null,
                "isbn": "0-395-19395-8",
                "price": null
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
}

我可以使用哪条JSON路径来检索包含bookcategoryauthorprice参数的title的第一个元素?要明确的是,我不希望任何 categoryauthorpricetitle参数 - 只有那些来自单书对象。此外,book数组的结构也各不相同(即其元素的数量和配置随时间而变化),因此我无法对任何内容进行硬编码。

1 个答案:

答案 0 :(得分:0)

我认为你的意思是:

$ .. book [?(@。category&& @ .author&& @ .price&& @ .title)]