基于特定值提取的Json路径

问题描述 投票:0回答:2

我有一个场景,我需要提取特定的JSON值。例如:我想摘录《世纪行情》一书的作者。我正在使用以下Jsonpath $..book[?(@.title eq 'Sayings of the Century')]。但是它什么也没回报我。你能告诉我如何做到这一点。

{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "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",
        "price": 8.99
      },
      { "category": "fiction",
        "author": "J. R. R. Tolkien",
        "title": "The Lord of the Rings",
        "isbn": "0-395-19395-8",
        "price": 22.99
      }
    ],
    "bicycle": {
      "color": "red",
      "price": 19.95
    }
  }
}
scala gatling
2个回答
1
投票

正确的语法是==,而不是eq

您可以使用http://ashphy.com/JSONPathOnlineEvaluator之类的在线工具测试您的表情>


0
投票

java和scala不同。您应该在scala中清楚显示jsonPath的类型。

© www.soinside.com 2019 - 2024. All rights reserved.