【问题标题】:Retrieving json data from a single object using JSONPath使用 JSONPath 从单个对象中检索 json 数据
【发布时间】:2016-11-05 03:17:40
【问题描述】:

鉴于下面的 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 路径来检索包含 categoryauthorpricetitle 参数的 book 的第一个元素?需要明确的是,我不想要 任何 categoryauthorpricetitle 参数——只有那些来自单个书籍对象的参数。此外,book 数组的结构会有所不同(即其元素的数量和配置会随着时间而变化),因此我无法真正硬编码任何内容。

【问题讨论】:

    标签: json jsonpath


    【解决方案1】:

    我认为你的意思是你想要:

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

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多