0

我正在尝试从下面提到的 json 数组中提取 id,其中 mfp 和 iwb 的 isExists=true。

   [
{
   "id": "fbe9ca5c-942b-48d8-9ffd-5f92ae64437a",
    "connectedDevices": {
      "mfp": {
        "isExists": true
      },
      "iwb": {
        "isExists": true
      }
    }
  },
  {
   "id": "4f90ef0f-c317-47ea-9013-53729477c379",
    "connectedDevices": {
      "mfp": {
        "isExists": true
      },
      "iwb": {
        "isExists": true
      }
    }
  },
   {
   "id": "98fe94ae-7e1b-42bb-8c2f-cae0f31105a0",
    "connectedDevices": {
      "mfp": {
        "isExists": false
      },
      "iwb": {
        "isExists": false
      }
    }
  },
   {
   "id": "b3f8ed32-e273-41d8-8caf-2024feeccd8c",
    "connectedDevices": {
      "mfp": {
        "isExists": false
      },
      "iwb": {
        "isExists": true
      }
    }
  }
  ]

使用 JSON Extractor 和 JSR223 PostProcessor 将值提取到数组中。

字符串[] ids ={“fbe9ca5c-942b-48d8-9ffd-5f92ae64437a”、“4f90ef0f-c317-47ea-9013-53729477c379”、“98fe94ae-7e1b-42bb-8c2f-cae0f31105a0”、“b3f8ed382-e-d7” -2024feeccd8c"}

String[] StatusM ={"true","true","false","false"}

String[] StatusI ={"true", "false", "false", "true"}
4

2 回答 2

0

目前尚不清楚“比较”是什么意思,但有一点很清楚:从 JMeter 3.1 开始,您应该使用 JSR223 测试元素和 Groovy 语言编写脚本。

原因在于:

  1. 与 Beanshell 相比,Groovy 的性能要好得多
  2. Groovy 支持所有现代 Java 功能,而 Beanshell 停留在Java 语言级别 5
  3. Groovy在 Java SDK 之上添加了许多增强功能,例如在集合操作方面:

于 2019-08-14T08:36:06.663 回答
0

id_ALL="fbe9ca5c-942b-48d8-9ffd-5f92ae64437a"、"4f90ef0f-c317-47ea-9013-53729477c379"、"98fe94ae-7e1b-42bb-8c2f-cae0f31105a0"、"b3f8ed32-e22732fecd8-8ca1"

StatusMFP_ALL="true","true","false","false"

StatusIwb_ALL = “真”、“假”、“假”、“真”

String[] ids = {${id_ALL}};

String[] StatusM = {${StatusMFP_ALL}};

String[] StatusI = {${StatusIwb_ALL}};

//获取数组长度

int count = Integer.parseInt(vars.get("id_matchNr"));
log.info( "countest" + vars.get("id_matchNr"));

ArrayList c = new ArrayList();

    for (int i = 0; i <=count-1; i++)
       {
         String M=StatusM[i];
         String I=StatusI[i];
              if(M=="true" || I=="true" )      
                {                  
                    String x=ids[i];                
                    c.add(x);                                                                                                         
                }      
      }            
        for (int i = 0; i < c.size(); i++) 
        {
              log.info(c.get(i));           
        }
        log.info(c.get(0));
于 2019-08-14T05:10:07.323 回答