赞
踩
- //导入json包
- import com.alibaba.fastjson.*;
- //获取获取请求的返回值
- String response_data = prev.getResponseDataAsString();
- //日志打印获取请求的返回值
- log.info(response_data);
-
- //将String类型的返回值构造成JSONObject对象
- JSONObject data_obj = JSONObject.parseObject(response_data);
-
- //获取data的值 并且转换成JSONObject对象
- data = data_obj.getString("data");
- JSONObject data_o = JSONObject.parseObject(data);
- //将records转成数组
- JSONArray sign_array=data_o.getJSONArray("sign");
- JSONArray unSign_array=data_o.getJSONArray("unSign");
- //获取数组长度
- int s = sign_array.size();
- int u = unSign_array.size();
- int len = s+u;
-
-
- log.info(len.toString());
-
- // 先把文件里的内容清空
- //FileWriter clrstream=new FileWriter("C:/Users/Administrator/Desktop/proof.csv",false);//本地存储文件路径
- //
- //BufferedWriter clrout = new BufferedWriter(clrstream);
- //clrout.write("");
- //clrout.close();
- //clrstream.close();
-
- //再次打开文件写入这次运行的结果 先把文件打开
- FileWriter fstream=new FileWriter("C:/Users/Administrator/Desktop/proof.csv",true);//本地存储文件路径
- BufferedWriter out = new BufferedWriter(fstream);
-
- log.info("1");
-
- for(int i=0;i<s;i++){ //循环获取数组里需要的值
- JSONObject r = (JSONObject)sign_array.getJSONObject(i);//把data里的每个json单独取出来 转换成JSONObject对象
- String taskId = r.get("taskId").toString(); //获取需要的值
- String userName = r.get("userName").toString();
- String idCard = r.get("idCard").toString();
- String qualiNo = r.get("qualiNo").toString();
- String certificateNo = r.get("certificateNo").toString();
- String certificateType = r.get("certificateType").toString();
- String graduationTime = r.get("graduationTime").toString();
- String itemType = r.get("itemType").toString();
- String major = r.get("major").toString();
- String graduationProofPdf = r.get("graduationProofPdf").toString();
- String graduationProofImg = r.get("graduationProofImg").toString();
-
- log.info(taskId);
- log.info(userName);
- log.info(idCard);
- log.info(qualiNo);
- log.info(certificateNo);
- log.info(certificateType);
- log.info(graduationTime);
- log.info(itemType);
- log.info(major);
- log.info(graduationProofPdf);
- // log.info(graduationProofImg);
-
- //写入文件
- out.write(taskId);
- out.write(",");
- out.write(userName);
- out.write(",");
- out.write(idCard);
- out.write(",");
- out.write(qualiNo);
- out.write(",");
- out.write(certificateNo);
- out.write(",");
- out.write(certificateType);
- out.write(",");
- out.write(",");
- out.write(graduationTime);
- out.write(",");
- out.write(itemType);
- out.write(",");
- out.write(major);
- out.write(",");
- out.write(graduationProofPdf);
- out.write(",");
- out.write(graduationProofImg);
- out.write(System.getProperty("line.separator"));
- }
-
- out.write(System.getProperty("line.separator")); //注册类 非注册类分开一行
-
- for(int i=0;i<u;i++){ //循环获取数组里需要的值
- JSONObject r = (JSONObject)unSign_array.getJSONObject(i);//把data里的每个json单独取出来 转换成JSONObject对象
- String taskId = r.get("taskId").toString(); //获取需要的值
- String userName = r.get("userName").toString();
- String idCard = r.get("idCard").toString();
-
- String certificateNo = r.get("certificateNo").toString();
- String workTypeName = r.get("workTypeName").toString();
- String postName = r.get("postName").toString();
-
- String graduationTime = r.get("graduationTime").toString();
- String graduationProofPdf = r.get("graduationProofPdf").toString();
- String graduationProofImg = r.get("graduationProofImg").toString();
-
- log.info(taskId);
- log.info(userName);
- log.info(idCard);
-
- log.info(certificateNo);
- log.info(workTypeName);
- log.info(postName);
- log.info(graduationTime);
- log.info(graduationProofPdf);
- // log.info(graduationProofImg);
-
- //写入文件
- out.write(taskId);
- out.write(",");
- out.write(userName);
- out.write(",");
- out.write(idCard);
- out.write(",");
- out.write(",");
- out.write(certificateNo);
- out.write(",");
- out.write(workTypeName);
- out.write(",");
- out.write(postName);
- out.write(",");
- out.write(graduationTime);
- out.write(",");
- out.write(",");
- out.write(",");
- out.write(graduationProofPdf);
- out.write(",");
- out.write(graduationProofImg);
- out.write(System.getProperty("line.separator"));
- }
-
-
- //关闭文件
- out.close();
- fstream.close();
接口返回的数据格式如下
{
"code": "000000",
"msg": "success",
"timestamp": "2024-04-24 09:45:06",
"data": {
"sign": [
{
"taskId": 7021,
"userName": "**",
"idCard": "530302199011012976",
"qualiNo": "536211910422003381",
"certificateNo": "云2532019202128859",
"certificateType": "市政公用工程(主项)",
"graduationTime": "2023-04-19 15:23:39",
"itemType": 1,
"major": "市政公用工程",
"graduationProofPdf": "https://yn-isp.oss-cn-hangzhou.aliyuncs.com/pdf_a610ac9a-cc93-4da4-9e03-19e58e5261e3.pdf",
"graduationProofImg": "https://yn-isp.oss-cn-hangzhou.aliyuncs.com/tar_2ee48607-9e7f-40d0-bf33-388dcc1ab2ea.jpg"
}
],
"unSign": [
{
"taskId": 102045095822,
"userName": "**",
"idCard": "**",
"certificateNo": "云建安B(2024)**",
"workTypeName": "安管三类人员",
"postName": "项目负责人",
"graduationTime": "2024-04-02 10:55:41",
"graduationProofPdf": "https://eibp-prd.oss-cn-hangzhou.aliyuncs.com/**.pdf",
"graduationProofImg": null,
"isView": 1
},
{
"taskId": 102044975875,
"userName": "**",
"idCard": "**",
"certificateNo": "云A**",
"workTypeName": "特种作业人员(省级)",
"postName": "焊工",
"graduationTime": "2024-03-31 12:36:49",
"graduationProofPdf": "https://eibp-prd.oss-cn-hangzhou.aliyuncs.com/**.pdf",
"graduationProofImg": null,
"isView": 1
}
}
]
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。