4

jmeterの最初のリクエストから取得したjsonレスポンスの一部をフェッチして、新しいHTTPリクエストを形成することに関するクエリがありました。

2 番目の HTTP 要求の一部として、二重引用符とコロンを含む 1 ブロックの情報 json (そのまま) を抽出したかったのです。

  {
      "details": [
        {
          "outBound": [
            {
              "info": {
                "date": "2016-08-11",
                "class": "M",
                "code": 70,
                "pricing": [
                  {
                    "totalAmount": 68.8,
                    "totalTaxAmount": 30.8,
                    "baseFareAmount": 38.0
                  }
                ],
                "totalAmount": 68.8,
                "totalDuration": 160,
            "referenceNumber": 1,
            "type": "RP",
            "id": 1
          },
          "segments": [
            { 
            "date": "2016-08-11",
            "className": "Standard (W)",
            "code": 70,
            "totalAmount": 68.8,
            "totalDuration": 160,
            "referenceNumber": 1,
            "type": "RP",
            "duration": 160,
            "number": "100"

            }
          ]
        },
        {
          "info": {
            "date": "2016-08-11",
            "class": "M",
            "code": 70,
            "pricing": [
              {
                "totalAmount": 78.8,
                "totalTaxAmount": 40.8,
                "baseFareAmount": 38.0
              }
            ],
            "totalAmount": 78.8,
            "totalDuration": 160,
            "referenceNumber": 2,
            "type": "RP",
            "id": 2
          },
          "segments": [
            { 
            "date": "2016-08-11",
            "className": "Standard (W)",
            "code": 70,
            "totalAmount": 78.8,
            "totalDuration": 160,
            "referenceNumber": 2,
            "type": "RP",
            "duration": 160,
            "number": "200"

            },
             { 
            "date": "2016-08-11",
            "className": "Standard (W)",
            "code": 70,
            "totalAmount": 78.8,
            "totalDuration": 160,
            "referenceNumber": 2,
            "type": "RP",
            "duration": 160,
            "number": "100"

            }
          ]
        }
      ],
      "resultCount": {
        "count1": 1,
        "count2": 1
      },
      "displayCount": 2
    }
  ]
    }

>Expected Output: 
    {
          "info": {
            "date": "2016-08-11",
            "class": "M",
            "code": 70,
            "pricing": [
              {
                "totalAmount": 68.8,
                "totalTaxAmount": 30.8,
                "baseFareAmount": 38.0
              }
            ],
            "totalAmount": 68.8,
            "totalDuration": 160,
            "referenceNumber": 1,
            "type": "RP",
            "id": 1
          },
          "segments": [
            { 
            "date": "2016-08-11",
            "className": "Standard (W)",
            "code": 70,
            "totalAmount": 68.8,
            "totalDuration": 160,
            "referenceNumber": 1,
            "type": "RP",
            "duration": 160,
            "number": "100",

            }
          ]
        }

JSON PATH POST Processor を使用してみましたが=、コロンの代わりに二重引用符のない文字列データの形式で抽出されたデータを取得していました。

4

1 に答える 1

11

この JSON パスの代わりにJSR223 PostProcessorを使用することをお勧めします。

  1. 上記の JSON を返すリクエストの子として JSR223 PostProcessor を追加します。
  2. groovy「言語」ドロップダウンで選択します
  3. 次のコードを JSR223 PostProcessor の「スクリプト」領域に挿入します。

    import groovy.json.JsonOutput
    import groovy.json.JsonSlurper
    
    def jsonSlurper = new JsonSlurper();
    def response = jsonSlurper.parseText(prev.getResponseDataAsString());
    def json = JsonOutput.toJson(response.details[0].outBound[0]);
    
    vars.put("json", json);
    
  4. 抽出された値を${json}必要に応じて参照する

参考文献:

于 2016-08-01T11:06:57.893 に答える