首页 万年历 万年历示例代码 万年历查询[Java]

万年历查询示例代码[Java]

作者:xiezhongpian 阅读数:2717 上传时间:2017-05-09

万年历查询

package api.jisuapi.calendar;

import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Query {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/calendar/query";
	public static final String date = "2015-10-22";

	public static void Get() {
		String result = null;
		String url = URL + "?appkey=" + APPKEY + "&date=" + date;

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONObject resultarr = json.optJSONObject("result");
				String year = resultarr.getString("year");
				String month = resultarr.getString("month");
				String day = resultarr.getString("day");
				String week = resultarr.getString("week");
				String lunaryear = resultarr.getString("lunaryear");
				String lunarmonth = resultarr.getString("lunarmonth");
				String lunarday = resultarr.getString("lunarday");
				String ganzhi = resultarr.getString("ganzhi");
				String shengxiao = resultarr.getString("shengxiao");
				String star = resultarr.getString("star");
				String humidity = "";
				if (resultarr.has("humidity")) {
					humidity = resultarr.getString("humidity");
				}
				String pressure = "";
				if (resultarr.has("pressure")) {
					pressure = resultarr.getString("pressure");
				}
				String windspeed = "";
				if (resultarr.has("humidity")) {
					windspeed = resultarr.getString("windspeed");
				}
				String winddirect = "";
				if (resultarr.has("pressure")) {
					winddirect = resultarr.getString("winddirect");
				}
				System.out.println(year + " " + month + " " + day + " " + week + " " + lunaryear + " " + lunarmonth
						+ " " + lunarday + " " + ganzhi + " " + shengxiao + " " + star);

				if (resultarr.opt("huangli") != null) {
					JSONObject huangli = resultarr.optJSONObject("huangli");
					String nongli = huangli.getString("nongli");
					String taishen = huangli.getString("taishen");
					String wuxing = huangli.getString("wuxing");
					String chong = huangli.getString("chong");
					String sha = huangli.getString("sha");
					String jiri = huangli.getString("jiri");
					String zhiri = huangli.getString("zhiri");
					String xiongshen = huangli.getString("xiongshen");
					String jishenyiqu = huangli.getString("jishenyiqu");
					String caishen = huangli.getString("caishen");
					String xishen = huangli.getString("xishen");
					String fushen = huangli.getString("fushen");
					System.out.println(
							nongli + " " + taishen + " " + wuxing + " " + chong + " " + sha + " " + jiri + " " + zhiri
									+ " " + xiongshen + " " + jishenyiqu + " " + caishen + " " + xishen + " " + fushen);
					JSONArray suici = huangli.optJSONArray("suici");
					for (int i = 0; i < suici.size(); i++) {
						System.out.println(suici.get(i));
					}
					JSONArray yi = huangli.optJSONArray("suici");
					for (int i = 0; i < yi.size(); i++) {
						System.out.println(yi.get(i));
					}
					JSONArray ji = huangli.optJSONArray("suici");
					for (int i = 0; i < ji.size(); i++) {
						System.out.println(ji.get(i));
					}

				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}