简体   繁体   English

jayway 2.2.0删除jsonpath中的括号

[英]jayway 2.2.0 remove brackets in jsonpath

We just started using 2.2.0 jayway and it seems to have many differences than 0.9.1. 我们刚刚开始使用2.2.0 jayway,它似乎与0.9.1有许多不同之处。

I am trying to get this item: $.[?(@.errorId=='200')].errorName[0] which worked in 0.9.1 by returning the value of errorName. 我试图得到这个项目: $.[?(@.errorId=='200')].errorName[0]通过返回errorName的值在0.9.1中工作。 In 2.2.0 it returns nothing. 在2.2.0中它什么都不返回。 If I change it to $.[?(@.errorId=='200')].errorName I get back a string WITH brackets "[result]" which does not work for me. 如果我把它改成$.[?(@.errorId=='200')].errorName我得到一个带括号“[result]”的字符串,这对我不起作用。 What should be the jsonPath in order to return a value and not an array? 什么应该是jsonPath以返回值而不是数组?

Yes, jayway json path behavior changed. 是的,jayway json的路径行为发生了变化。 Now, whenever you use filter ('?') you will receive a java list in response. 现在,无论何时使用过滤器('?'),您都会收到一个java列表作为响应。 See "Indefinite paths" in https://github.com/jayway/JsonPath#what-is-returned-when 请参阅https://github.com/jayway/JsonPath#what-is-returned-when中的 “无限路径”

So you have to .get(0) on json path result... 所以你必须在json路径结果上有.get(0) ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM