即使 JSON 路径有效,karate.jsonPath 也不起作用
The karate.jsonPath is not working even if the JSON Path is valid
我的脚本如下:
* def inputJson = createJson();
* print inputJson
* def customerName = karate.jsonPath(inputJson, "$.customerDetails[0]")
* print customerName
给我这个错误:
javascript evaluation failed: karate.jsonPath(inputJson, "$.customerDetails[0]"), Property ['customerDetails'] not found in path $
尽管 json路径有效,如下所示:
想知道这里有没有人遇到过同样的情况?你能告诉我如何纠正这个问题吗?提前谢谢你。
注意: 我在控制台中打印了 json 并在上面的屏幕截图中检查 json 路径时使用了相同的内容。我还在 JSON Lint 中验证了我使用的 json,它是有效的。
在这种情况下您不需要 JsonPath:
* def customerName = inputJson.customerDetails[0]
但如果您在使用 JsonPath 时遇到问题,请尝试 karate.filter()
作为替代方法:
我的脚本如下:
* def inputJson = createJson();
* print inputJson
* def customerName = karate.jsonPath(inputJson, "$.customerDetails[0]")
* print customerName
给我这个错误:
javascript evaluation failed: karate.jsonPath(inputJson, "$.customerDetails[0]"), Property ['customerDetails'] not found in path $
尽管 json路径有效,如下所示:
想知道这里有没有人遇到过同样的情况?你能告诉我如何纠正这个问题吗?提前谢谢你。
注意: 我在控制台中打印了 json 并在上面的屏幕截图中检查 json 路径时使用了相同的内容。我还在 JSON Lint 中验证了我使用的 json,它是有效的。
在这种情况下您不需要 JsonPath:
* def customerName = inputJson.customerDetails[0]
但如果您在使用 JsonPath 时遇到问题,请尝试 karate.filter()
作为替代方法: