我正在尝试在Java rest上实现一种方法,以确保找到查询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]
我做错了什么?
答案 0 :(得分:0)
发现了问题。
我将“ =”而不是“ ==“