如何使用正则表达式提取器或任何其他提取器(Xpath,Beanshell等)从下面给出的Json中提取所有Id的值


[
    {
        "id": 1,
        "name": "MetaOperationN1",
        "type": "Operation"
    },
    {
        "id": 2,
        "name": "GreenOper2",
        "type": "Operation"
    },
    {
        "id": 3,
        "name": "GreenOper4",
        "type": "Operation"
    },
    {
        "id": 4,
        "name": "GreenOper5",
        "type": "Operation"
    },
    {
        "id": 5,
        "name": "GreenOper6",
        "type": "Operation"
    },
    {
        "id": 6,
        "name": "GreenOper7",
        "type": "Operation"
    },
    {
        "id": 7,
        "name": "GreenOper8",
        "type": "Operation"
    },
    {
        "id": 8,
        "name": "GreenOper9",
        "type": "Operation"
    },
    {
        "id": 9,
        "name": "GreenOper10",
        "type": "Operation"
    },
    {
        "id": 10,
        "name": "GreenOper11",
        "type": "Operation"
    }
]
  1. 使用正则表达式提取器进行以下配置:

    • 参考名称:任何有意义的,即ID
    • 正则表达式:"id": (d+),
    • 模板:$1$
    • 不相匹配。: -1
  2. 使用JSON路径提取器(可通过JMeter插件)

    • 参考名称:任何你想要的,即ID
    • JSONPath表达式:$..id

在这两种情况下,您将得到id列表为:

ID_1=1
ID_10=10
ID_2=2
ID_3=3
ID_4=4
etc.

有关安装JSON路径提取器和JSON路径语言的更多信息,请查看在JMeter中使用XPath提取器(向下滚动到"解析JSON")

不要使用正则表达式解析json文档。通过引用

很容易做到

如果你想使用正则表达式…继续:

"id": (d+)

并使用$1

提取id

最新更新