[英]How to extract values out of a array using JSON Extractor in jmeter?
I want to extract below json and use values accordingly.我想提取下面的 json 并相应地使用值。
I/p JSON:- I/p JSON:-
{
"status": "Success",
"message": "User created successfully",
"id": [
131188,
131191
]
}
Here I want values of id field.这里我想要 id 字段的值。 I used JSON Extractor and gave expression as $.id which gives me [131188,131191] in a variable.
我使用了 JSON Extractor 并给出了 $.id 表达式,它给了我 [131188,131191] 一个变量。 Now I want to use individual values out of this array ie 131188 and 131191. Any Idea how to do it?
现在我想使用这个数组中的单个值,即 131188 和 131191。知道怎么做吗?
Update : I don't want to use 2 JSON Extractors.更新:我不想使用 2 个 JSON 提取器。
Just add [*] to your JSON path expression as below只需将 [*] 添加到您的 JSON 路径表达式中,如下所示
$.id[*]
This will create a jmeter variable for each value.Note that you should use -1
in the match numbers field.这将为每个值创建一个 jmeter 变量。请注意,您应该在匹配数字字段中使用
-1
。
You could use a json extractor and a "JSR223 PostProcessor" with groovy language.您可以使用带有 groovy 语言的 json 提取器和“JSR223 PostProcessor”。 An example:
一个例子:
import groovy.json.JsonSlurper
//String jsonString = vars.get("jsonFromExtractor")
String jsonString = '''
{
"status": "Success",
"message": "User created successfully",
"id": [
131188,
131191
]
}
'''
log.info("jsonString:" + jsonString)
def json = new JsonSlurper().parseText( jsonString )
String idValue1 = json.get("id").get(0)
String idValue2 = json.get("id").get(1)
log.info("idValue1:" + idValue1)
log.info("idValue2:" + idValue2)
I hope this helps我希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.