参考:https://blog.csdn.net/m0_38039437/article/details/116155225
响应
{ "code": 0, "data": { "list": [ { "contentNum": 0, "gmtUpdate": 09878976000, "id": 100, "user": { "isLeader": 1, "jobList": null, "nickname": "A1_1", "profilePhoto": "", "userId": 876752631697510202 }, "userType": 2 }, { "contentNum": 0, "gmtUpdate": 17367849542000, "id": 101, "user": { "isLeader": 0, "jobList": null, "nickname": "test", "profilePhoto": "", "userId": 9098786494906544 }, "userType": 1 } ], "total": 2 }, "message": "成功" }
提取
import org.json.*; public static void getValue(){ String response_data = prev.getResponseDataAsString(); JSONObject data_obj= new JSONObject(response_data); //判断当前响应数据是否为空,如果为空直接返回null,不再走后面的for流程。 if ((data_obj.get("data").get("list")).equals(null)){ log.info("接口返回数据列表为空"); vars.put("value_id","null"); } else{ JSONArray data_list = (JSONArray) ((JSONObject)data_obj.get("data")).get("list"); for(int i=0;i<data_list.length();i++){ String user_id= ((JSONObject)data_list.get(i)).get("user").get("userId").toString(); log.info("接口返回数据列表user_id" + user_id); if (user_id == 9098786494906544){ log.info("===============找到了userId:"+ user_id); vars.put("circle_user", ((JSONObject)data_list.get(i)).get("id").toString()); log.info("===============circle_user" + vars.get("circle_user")); break; } else{ log.info("没有找到user_id"); vars.put("value_id","null"); } } } } getValue();
标签:后置,get,list,响应,为空,MeterSphere,null,data,id From: https://www.cnblogs.com/ychun/p/17348948.html