java解析百度日历API的节假日Json串

百度的接口没有更新2021年节假日 ,文章下方再补一个第三方接口
百度日历Json接口
只能解析当年及以前年份的节假日,因为下一年的节假日需要等国务院发布节假日,想要实时获取,可以自定义定时任务每年的第一天去查询百度的接口https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query=2020&resource_id=6018&format=json

数据中的状态是2 做了下判断 只有1的状态是节假日

在这里插入图片描述

根据年份解析百度接口的节假日,然后封装到集合中

public static Map<Date, DayStatusEnum> holidayByList(String year){
   
		String httpUrl = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query="+year+"&resource_id=6018&format=json";
		BufferedReader reader = null;
		String result = null;
		StringBuffer sbf = new StringBuffer();
		Map<Date,DayStatusEnum> dateMap = new HashMap<Date,DayStatusEnum>();
		try {
   
			URL url = new URL(httpUrl);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("GET");
			connection.connect();
			InputStream is = connection.getInputStream();
			reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
			String strRead = null;
			while ((strRead = reader.readLine()) != null) {
   
				sbf.append(strRead);
				sbf.append("\r\n");
			}
			reader.
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值