jmeter-postプロセッサー-BeanShell PostProcessor-json抽出-json値変更-get

1. jsonパッケージをインポートする

 

2. JSON jarパッケージ-時間形式パッケージ(変更された値が使用されます)をインポートします

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
// java.text.SimpleDateFormat;をインポートします 
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

3.システム変数-responsedataを取得します 

文字列response_data = prev.getResponseDataAsString();

4. json data.param.ciType.descriptionのフィールドを変更しますこのフィールドを変更します

JSONObject jsonObject = JSON.parseObject(response_data); 
JSONObject paramJson =(JSONObject)((JSONObject)jsonObject.get( "data"))。get( "param" ); 
JSONObject ciTypeJsom =(JSONObject)paramJson.get( "ciType" ); 
ciTypeJsom.put( "description"、ciTypeJsom.get( "description")+ "_ auto _" + LocalDateTime.now()。format(DateTimeFormatter.ofPattern( "yyyyMMddHHmm" )));); 

// SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmm");
// ciTypeJsom.put( "description"、ciTypeJsom.get( "description")+ "_ auto _" + sdf.format(new Date())); 
文字列responseData_a = jsonObject.toString();

5.システム時間-取得する2つの方法。パッケージをインポートすることを忘れないでください。元の説明は、説明の値+ + _auto_ +時間になります。

import java.text.SimpleDateFormat; 

SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmm" ); 
ciTypeJsom.put( "description"、ciTypeJsom.get( "description")+ "_ auto _" + sdf.format(new Date()));
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; 

ciTypeJsom.put( "description"、ciTypeJsom.get( "description")+ "_ auto _" + LocalDateTime.now()。format(DateTimeFormatter.ofPattern( "yyyyMMddHHmm")));

6.変数を保存する

vars.put( "responseData_b"、responseData_a);

 

7. jsonで文字列を取得する-次の転送


元のリンク:https://blog.csdn.net/aduocd/java/article/details/80351719

1. シナリオ1:要求応答でデータを取得し、

インポート com.alibaba.fastjson を保存します*;   // パッケージを紹介します。このパッケージの必要性を置くことにする。<インストールディレクトリ> \のapache-のJMeter-3.2 \ libに\ extに

// 取得したデータ

の文字列レスポンス = prev.getResponseDataAsString();   // 応答を取得

JSONObject responseObj = JSON.parseObject(レスポンス);   / / Response全体はJSONオブジェクトです

JSONObject resObj = responseObj.getJSONObject( "res");   // オブジェクトの一部を取得します。つまり、json文字列の{}の内容

JSONArray listArray = resObj.getJSONArray( "list");   // リストを取得します。つまり、json文字列の[]の内容

// データを保存

// 1)リスト

int len = listArray.size();

forint i = 0; i <len; i ++ ){ 

    temp [i] = listArray.get(i).getString( "name" ); 

} 

vars.put( "names"、Arrays.toString(temp));   // JMeter変数に保存、vars.putは文字列のみを保存できるため、ここではtoString()を使用して変換します

// 2)文字列型

String id = resObj.get( "id");   // 特定のオブジェクトを取得します文字列の内容。

vars.put( "id"、id);   // JMeter変数に保存し、次のコンポーネントを使用できます

// 3)整数型

Integer no = resObj.get( "id");  // オブジェクト全体を取得しますコンテンツのタイプ。

vars.put( "no"、no.toString());    //JMeter変数に保存すると、vars.putは文字列のみを保存できるため、変換
 
2にはtoString()を使用しますシナリオ2:データベースでクエリされたデータを取得し、

前提を保存します。データはJDBCリクエストで取得されています。詳細については、「JDBCRequestの使用」を参照してください。

select total_cash from t_cash where user_name = "tom" ; 

Result variable name in value is:result 

String cash_new = vars.getObject( "result")。get(0).get( "total_cash" 
 .toString (); 
vars .put( "cash_new"、cash_new);   // 操作前のこのステップと同じで、詳細はありません。保存された変数は、cash_oldという名前です。

 

おすすめ

転載: www.cnblogs.com/shishibuwan/p/12683455.html