[英]Parsing json list from Gatling response body
The tested site responds with following json:测试站点响应以下 json:
{
results: [
foo1,
foo2,
...
]
}
I would like to extract only the size of list under "results" key.我想只提取“结果”键下的列表大小。
I know I can use jsonPath to extract json keys, but it returns String and I don't know how to read it as List:我知道我可以使用 jsonPath 提取 json 键,但它返回字符串,我不知道如何将其读取为列表:
exec(http(requestName)
.get("/result/${" + responseId + "}")
.check(status is 200)
.check(jsonPath("results").saveAs(responseId))
)
Is there a way of further parsing the json to get list entity?有没有办法进一步解析 json 以获取列表实体?
For anyone having this particular use-case.对于任何有这个特定用例的人。 There is no need for additional json parsing, instead you should write:
不需要额外的 json 解析,而是应该写:
exec(http(requestName)
.get("/result/${" + responseId + "}")
.check(status is 200)
.check(jsonPath("$").ofType[Seq[Any]].saveAs(responseBodyId)))
)
jsonPath("path").ofType[Seq[Any]]
matches Seq[Any], so it can either to be used to getting seq size or further parsing.匹配 Seq[Any],因此它可以用于获取 seq 大小或进一步解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.