gpt4 book ai didi

java - 放心 jsonpath findAll 没有按预期工作

转载 作者:行者123 更新时间:2023-12-02 06:12:04 26 4
gpt4 key购买 nike

我正在尝试在java上实现一种方法,确保找到查询JSON文件的值。为此,我使用 io.restassured.path.json.JsonPath 库中的 JSONPath 的 findAll 方法来访问所需的值。

出于某种未知的原因,它从路径获取所有值,而不是我指定的值

 System.out.println(restApi.getValueFromJson(filePath,"purchases.purchase.insuredItems.travelers.travelerPurchase.findAll{it.title = 'Frau'}"));



[{professionalRisk=Medium, firstName=Sh�ra, lastName=Y�ung, riskActivity=Recreational sports, dateOfBirth=1991-12-12, @id=2, title=Frau, individualTravelPrice={#text=20, @currency=EUR}, @role=INSURED}, {professionalRisk=Medium, firstName=Shashank, lastName=Tripathi, riskActivity=Recreational sports, dateOfBirth=1995-05-23, @id=3, title=Frau, individualTravelPrice={#text=100, @currency=EUR}, @role=INSURED}, {professionalRisk=Medium, firstName=J�hn, lastName=Y�nus, riskActivity=Recreational sports, dateOfBirth=2017-12-12, @id=4, title=Frau, individualTravelPrice={#text=258.15, @currency=EUR}, @role=INSURED}, {professionalRisk=Medium, firstName=S�m�el, lastName=Polo, riskActivity=Recreational sports, dateOfBirth=1940-05-10, @id=5, title=Frau, individualTravelPrice={#text=10072, @currency=EUR}, @role=INSURED}, {professionalRisk=Medium, firstName=Gli �ernch, lastName=Fedrick, riskActivity=Recreational sports, dateOfBirth=1930-12-12, @id=6, title=Frau, individualTravelPrice={#text=1000, @currency=EUR}, @role=INSURED}]

而不是

[{professionalRisk=Medium, firstName=Sh�ra, lastName=Y�ung, riskActivity=Recreational sports, dateOfBirth=1991-12-12, @id=2, title=Frau, individualTravelPrice={#text=20, @currency=EUR}, @role=INSURED}]

显然,如果我这样做

System.out.println(restApi.getValueFromJson(filePath,"purchases.purchase.insuredItems.travelers.travelerPurchase.findAll{it.title = 'Frau'}.dateOfBirth"));

需要

[1991-12-12, 1995-05-23, 2017-12-12, 1940-05-10, 1930-12-12]

而不是

[1991-12-12]

我做错了什么?

最佳答案

发现问题了。

我用“=”而不是“==”进行比较

关于java - 放心 jsonpath findAll 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55900672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com