引入fastjson和hutool
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.0</version>
</dependency>
返回1代表正常休息日,2代表国家法定节假日
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import java.util.HashMap;
import java.util.TreeMap;
public class TestHoliday {
public static void main(String[] args) {
String yearMonth = DateUtil.format(DateUtil.date(), "yyyyMM");
// String yearMonth = "202105";
String url = "https://zhiwei-tech.com/console/api/holiday/" + yearMonth;
String body = HttpRequest.get(url).setEncodeUrlParams(true).execute().body();
HashMap<String, String> yearMonthMap =
JSON.parseObject(body, new TypeReference<HashMap<String, String>>() {
});
String monthHoliday = yearMonthMap.get(yearMonth);
TreeMap<Integer, Integer> treeMap =
JSON.parseObject(monthHoliday, new TypeReference<TreeMap<Integer, Integer>>() {
});
for (Integer key : treeMap.keySet()) {
System.out.println(key + "----------" + treeMap.get(key));
}
}
}
结果
1----------2
2----------2
3----------2
4----------2
5----------2
9----------1
15----------1
16----------1
22----------1
23----------1
29----------1
30----------1