Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex JSON响应上两个字段的正则表达式-Jmeter_Regex_Json_Jmeter - Fatal编程技术网

Regex JSON响应上两个字段的正则表达式-Jmeter

Regex JSON响应上两个字段的正则表达式-Jmeter,regex,json,jmeter,Regex,Json,Jmeter,假设我有这个JSON响应: [ { "id": "15", "userId": "1", "new": "true", "date": "08/12/2013", "text": "…" }, { "id": "16", "userId": "1", "new": "false", "date": "08/12/2013", "text":

假设我有这个JSON响应:

    [
     {
      "id": "15",
      "userId": "1",
      "new": "true",
      "date": "08/12/2013",
      "text": "…"
     },
     {
      "id": "16",
      "userId": "1",
      "new": "false",
      "date": "08/12/2013",
      "text": "…"
     }
    ]
每个对象的id的常规expresión提取器将具有以下配置:

    Reference name: object
    Regular Expression: "id":"(.+?)"
    Template: $1$
    Match No: -1
    Default value: null
我需要的是从每个对象中提取idnew,以便在ForEach控制器中一起使用它们。我需要一些关于正则表达式的帮助

    Reference name: object
    Regular Expression: ¿? "id":"(.+?)" ¿? "new":"(.+?)" ¿?
    Template: $1$$2$
    Match No: -1
    Default value: null
此外,如何引用对象的每个特定部分${object_1}${object_2}


编辑:对不起,我忘了提到我具体使用的是Jmeter。

这是JSON。那么,为什么不将其解析为JSON呢。
这样做很简单。我使用了Java解析器

String jsonData = "[\r\n" + 
        "        {\r\n" + 
        "         \"id\": \"15\",\r\n" + 
        "         \"userId\": \"1\",\r\n" + 
        "         \"new\": \"true\",\r\n" + 
        "         \"date\": \"08/12/2013\",\r\n" + 
        "         \"text\": \"…\"\r\n" + 
        "        },\r\n" + 
        "        {\r\n" + 
        "         \"id\": \"16\",\r\n" + 
        "         \"userId\": \"1\",\r\n" + 
        "         \"new\": \"false\",\r\n" + 
        "         \"date\": \"08/12/2013\",\r\n" + 
        "         \"text\": \"…\"\r\n" + 
        "        }\r\n" + 
        "       ]";

JSONArray jsonRoot = new JSONArray(jsonData);

for (int i = 0; i < jsonRoot.length(); i++) {
    JSONObject jsonObj = jsonRoot.getJSONObject(i);
    System.out.println("Object_" + (i+1) + " = id: " + jsonObj.getString("id") +
            ", new: " + jsonObj.getString("new"));
您可以设置:

然后使用ForEach控制器,或者如果您只需要一些值,那么您将拥有:

id_1=15

id_2=16 ... new_1=真

new_2=false

索引是相关的

否则,您可以查看以下内容:


如果有帮助的话,我已经为这个主题制作了一个视频。看看吧


忘了提到我使用的是Jmeter。对不起@亚历克斯,我为丢失标签道歉。我也很抱歉!
Object_1 = id: 15, new: true
Object_2 = id: 16, new: false