在空手道中使用 jsonpath 检索 json 数组对象时出错
Getting error while retrieving json array object using jsonpath in karate
我在使用 jsonpath 检索值 A、B、C 时遇到错误
错误:
karate.jsonPath(response, "$.code[*~]"), com.jayway.jsonpath.InvalidPathException: Expected wildcard token to end with ']'
- def value = karate.jsonPath(response, "$.code[*~]")
- def value_expected = ["A","B","C"]
- 匹配值仅包含 value_expected
回复如下:
{
"code": {
"A": [
{
"codeValue": 510575,
"Key": "XYZ"
}
],
"B": [
{
"codeValue": 510575,
"Key": "XYZ"
}
],
"C": [
{
"codeValue": 510575,
"Key": "XYZ"
}
]
}
}
我不建议在这种情况下使用 JsonPath,例如拿钥匙,真的很难。请使用空手道 JSON 变换:github
* def keys = []
* def fun = function(k, v){ karate.appendTo(keys, k) }
* karate.forEach(response.code, fun)
* match keys == ['A', 'B', 'C']
我在使用 jsonpath 检索值 A、B、C 时遇到错误
错误:
karate.jsonPath(response, "$.code[*~]"), com.jayway.jsonpath.InvalidPathException: Expected wildcard token to end with ']'
- def value = karate.jsonPath(response, "$.code[*~]")
- def value_expected = ["A","B","C"]
- 匹配值仅包含 value_expected
回复如下:
{
"code": {
"A": [
{
"codeValue": 510575,
"Key": "XYZ"
}
],
"B": [
{
"codeValue": 510575,
"Key": "XYZ"
}
],
"C": [
{
"codeValue": 510575,
"Key": "XYZ"
}
]
}
}
我不建议在这种情况下使用 JsonPath,例如拿钥匙,真的很难。请使用空手道 JSON 变换:github
* def keys = []
* def fun = function(k, v){ karate.appendTo(keys, k) }
* karate.forEach(response.code, fun)
* match keys == ['A', 'B', 'C']