Java实时获取天气(免费接口)


/** 天气URL/
public static final String TQ_URL="https://tianqiapi.com/api.php";
//TODO https://tianqiapi.com/api.php?style=tq //有更多内容
/** 抽取参数空格符
/
public static final String K_G="\u3000";

Calendar now = Calendar.getInstance();
String html = HttpClientUtil.getFromUrl(TQ_URL,null);
Document doc = Jsoup.parse(html);
Elements rows = doc.select("em");
String rtn = rows.get(0).text()+K_G+rows.get(1).text()+K_G+rows.get(2).text();
String paramValue = "今天是:"+now.get(Calendar.YEAR)+"年"+(now.get(Calendar.MONTH) + 1)+"月"+now.get(Calendar.DAY_OF_MONTH)+"日"+K_G+week+K_G+rtn;
(效果见附图)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM