引入依赖
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.12</version>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
{
"projCode":"100001-1-1-2",
"projName":"计划项目2",
"selfAssessmentScore":92,
"id":2,
"produce":{
"number":[
{
"kpiName":"数量指标",
"kpiDescription":"计划项目22022第4产出指标-数量指标",
"kpiScore":10,
"id":4698,
"realScore":10,
"problemsAndSolutions":""
}
],
"cost":[
{
"kpiName":"成本指标",
"kpiDescription":"计划项目22022第4产出指标-成本指标",
"kpiScore":10,
"id":4700,
"realScore":6,
"problemsAndSolutions":""
}
],
"quality":[
{
"kpiName":"质量指标",
"kpiDescription":"计划项目22022第4产出指标-质量指标",
"kpiScore":10,
"id":4699,
"realScore":9,
"problemsAndSolutions":""
}
]
},
"benefit":{
"militaryEconomy":[
{
"kpiName":"军事经济指标",
"kpiDescription":"计划项目22022第4效益指标-军事经济指标",
"kpiScore":10,
"id":4703,
"realScore":5,
"problemsAndSolutions":""
}
],
"actualEffect":[
{
"kpiName":"实效指标",
"kpiDescription":"计划项目22022第4效益指标-实效指标",
"kpiScore":10,
"id":4701,
"realScore":6,
"problemsAndSolutions":""
}
],
"sustainableImpact":[
{
"kpiName":"可持续指标",
"kpiDescription":"计划项目22022第4效益指标-可持续指标",
"kpiScore":10,
"id":4704,
"realScore":7,
"problemsAndSolutions":""
}
],
"ability":[
{
"kpiName":"能力指标",
"kpiDescription":"计划项目22022第4效益指标-能力指标",
"kpiScore":10,
"id":4702,
"realScore":6,
"problemsAndSolutions":""
}
]
}
}
//此处仅测试get方法
//1、创建客户端
CloseableHttpClient httpClient = HttpClients.createDefault();
//2、创建Http的请求方式get,post etc... 需要传入请求地址
//此处输入B项目的ControllerDemo类中select()方法的请求url
HttpGet httpGet = new HttpGet("http://106.13.124.95:10888/manager/expert/launchEvaluation?projId=2&type=2&year=2022");
//3、httpClient执行请求,并获取返回结果
CloseableHttpResponse response = httpClient.execute(httpGet);
//4、输出获取到的结果
//从response中取出返回的entity
HttpEntity entity = response.getEntity();
// 把实体转成字符串
String s = EntityUtils.toString(entity);
AssProGrade assProGrade = new AssProGrade();
// 把字符串转成JSON对象
JSONObject jsonObject = JSONObject.parseObject(s);
// 获取jsonObject对象中的data数据
JSONObject data = jsonObject.getJSONObject("data");
// 获取二级指标 数量指标
JSONArray number = data.getJSONObject("produce").getJSONArray("number");
JSONArray cost = data.getJSONObject("produce").getJSONArray("cost");
JSONArray quality = data.getJSONObject("produce").getJSONArray("quality");
JSONArray militaryEconomy = data.getJSONObject("benefit").getJSONArray("militaryEconomy");
JSONArray actualEffect = data.getJSONObject("benefit").getJSONArray("actualEffect");
JSONArray sustainableImpact = data.getJSONObject("benefit").getJSONArray("sustainableImpact");
JSONArray ability = data.getJSONObject("benefit").getJSONArray("ability");
// 获取三级指标的值
for (Object obj : number) {
JSONObject numberData = (JSONObject) JSON.toJSON(obj);
}