首页 星座运势 星座运势示例代码 星座运势查询[Java]

星座运势查询示例代码[Java]

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

星座运势查询

package api.jisuapi.astro;

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

public class Fortune {

	public static final String APPKEY = "your_appkey_here";// 你的appkey
	public static final String URL = "https://api.jisuapi.com/astro/fortune";
	public static final int astroid = 1;
	public static final String date = "2016-01-19";

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

		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 astroid = resultarr.getString("astroid");
				String astroname = resultarr.getString("astroname");
				System.out.println(astroid + " " + astroname);
				if (resultarr.opt("year") != null) {
					JSONObject year =  resultarr.optJSONObject("year");
					String date = year.getString("date");
					String summary = year.getString("summary");
					String money = year.getString("money");
					String career = year.getString("career");
					String love = year.getString("love");
					System.out.println(date + " " + summary + " " + money + " " + career + " " + love);
				}
				if (resultarr.opt("week") != null) {
					JSONObject week = resultarr.optJSONObject("week");
					String date = week.getString("date");
					String money = week.getString("money");
					String career = week.getString("career");
					String love = week.getString("love");
					String health = week.getString("health");
					String job = week.getString("job");
					System.out.println(date + " " + money + " " + career + " " + love + " " + health + " " + job);
				}
				if (resultarr.opt("today") != null) {
					JSONObject today = resultarr.optJSONObject("today");
					String date = today.getString("date");
					String presummary = today.getString("presummary");
					String star = today.getString("star");
					String color = today.getString("color");
					String number = today.getString("number");
					String summary = today.getString("summary");
					String money = today.getString("money");
					String career = today.getString("career");
					String love = today.getString("love");
					String health = today.getString("health");
					System.out.println(date + " " + presummary + " " + star + " " + color + " " + number + " " + summary
							+ " " + money + " " + career + " " + love + " " + health);
				}
				if (resultarr.opt("tomorrow") != null) {
					JSONObject tomorrow = resultarr.optJSONObject("tomorrow");
					String date = tomorrow.getString("date");
					String presummary = tomorrow.getString("presummary");
					String star = tomorrow.getString("star");
					String color = tomorrow.getString("color");
					String number = tomorrow.getString("number");
					String summary = tomorrow.getString("summary");
					String money = tomorrow.getString("money");
					String career = tomorrow.getString("career");
					String love = tomorrow.getString("love");
					String health = tomorrow.getString("health");
					System.out.println(date + " " + presummary + " " + star + " " + color + " " + number + " " + summary
							+ " " + money + " " + career + " " + love + " " + health);
				}
				if (resultarr.opt("month") != null) {
					JSONObject month = resultarr.optJSONObject("month");
					String date = month.getString("date");
					String summary = month.getString("summary");
					String money = month.getString("money");
					String career = month.getString("career");
					String love = month.getString("love");
					System.out.println(date + " " + summary + " " + money + " " + career + " " + love);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}