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