jmeter 自定义变量 json字符串 解析json对象变为用户变量
用户变量为json {\"#at_beforeDate#\":\"2023-10-19 17:51:10\",\"#at_phone#\":\"18617121598\",\"#at_username#\":\"张琳琳\",\"#at_date#\":\"2023-10-19 17:51:10\",\"#at_random_6#\":\"5\",\"#at_random_4#\":\"4\",\"#at_add#\":\"山东省滨州市阳信县张琳琳村\",\"#at_random_10#\":\"4\",\"#at_username_2#\":\"景雨泽\",\"#at_bank#\":\"6263454728124954892\",\"#at_random_12#\":\"5\",\"#at_name#\":\"at_xYyTf\",\"#at_phone_1#\":\"18617121111\",\"#at_area#\":\"371622\",\"#at_email#\":\"18309643180@163.com\",\"#at_random_3#\":\"2\",\"#at_random_1#\":\"1\",\"#at_random_11#\":\"7\",\"#at_random_55#\":\"47\",\"#at_city#\":\"371600\",\"#at_idcard#\":\"812532200002151310\",\"#at_username_1#\":\"申屠明达\",\"#at_random_8#\":\"6\",\"#at_province#\":\"370000\",\"#at_nextDate#\":\"2023-10-19 17:51:10\",\"#at_phone_2#\":\"18617121122\",\"#at_time#\":\"1697709070965\"}
添加预处理器
代码块
import com.alibaba.fastjson.JSONObject;
import java.util.*;
log.info("====================");
//获取接口响应
String responsData = "${responsData}";
log.info("===================="+responsData);
JSONObject resData = JSONObject.parseObject(responsData);
log.info("===================="+resData);
//遍历key和value
for(String key: resData.keySet()){
vars.put(key,resData.get(key));
log.info(key+"===================="+resData.get(key));
}
json 解析完成
创作不易,转摘请标明出处。如果有意一起探讨测试相关技能可加博主QQ 771268289 博主微信:ding17121598
本文来自博客园,作者:怪圣卡杰,转载请注明原文链接:https://www.cnblogs.com/dwdw/p/17789907.html