在使用其中包含 xpath 的正则表达式时,我遇到了 jayway jsonpath 的问题。这是我的json:
{
"status": "success",
"resources": [
{
"id": "Attachment-20796b26-7a16-4a3d-b53c-b30d9f3cb798.TXT",
"name": "1996032897__test1.CREDITPRINTFILE",
"mimeType": "text/plain",
"url": "https://test.com"
}
]
}
这是我的表达:资源[?(/__test1.CREDITPRINTFILE/.test(@.name))]
我收到以下错误:
Exception in thread "main" com.jayway.jsonpath.InvalidPathException: Expected path node
at com.jayway.jsonpath.internal.filter.ValueNode.asPathNode(ValueNode.java:53)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readExpression(FilterCompiler.java:204)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalANDOperand(FilterCompiler.java:189)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalAND(FilterCompiler.java:151)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalOR(FilterCompiler.java:131)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalANDOperand(FilterCompiler.java:184)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalAND(FilterCompiler.java:151)
at com.jayway.jsonpath.internal.filter.FilterCompiler.readLogicalOR(FilterCompiler.java:131)
at com.jayway.jsonpath.internal.filter.FilterCompiler.compile(FilterCompiler.java:77)
at com.jayway.jsonpath.internal.filter.FilterCompiler.compile(FilterCompiler.java:53)
at com.jayway.jsonpath.internal.path.PathCompiler.readFilterToken(PathCompiler.java:461)
at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:141)
at com.jayway.jsonpath.internal.path.PathCompiler.readPropertyOrFunctionToken(PathCompiler.java:237)
at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:151)
at com.jayway.jsonpath.internal.path.PathCompiler.readDotToken(PathCompiler.java:171)
at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:145)
at com.jayway.jsonpath.internal.path.PathCompiler.readContextToken(PathCompiler.java:124)
at com.jayway.jsonpath.internal.path.PathCompiler.compile(PathCompiler.java:58)
at com.jayway.jsonpath.internal.path.PathCompiler.compile(PathCompiler.java:75)
at com.jayway.jsonpath.JsonPath.<init>(JsonPath.java:101)
at com.jayway.jsonpath.JsonPath.compile(JsonPath.java:467)
at com.jayway.jsonpath.internal.JsonContext.read(JsonContext.java:87)
at daniel.TestJsonPath.main(TestJsonPath.java:72)
我也尝试在在线评估工具中使用相同的表达式:https ://jsonpath.herokuapp.com/
Jayway - 给出同样的错误 - 预期的路径节点 Gatling, Nebhale - Goessner 出错 - 给了我有效的结果
我认为我正在使用最新版本的 jayway -
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.4.0</version>
</dependency>
问题:如果 jayway 不能解决这些表达式,有没有其他的 java 库可以用来解决这些问题?