首页 历史上的今天 历史上的今天示例代码 历史上的今天查询[Java]

历史上的今天查询示例代码[Java]

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

历史上的今天查询

package api.jisuapi.todayhistory;

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/todayhistory/query";
	public static final String month = "1";
	public static final String day = "2";

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

		try {
			result = HttpUtil.sendGet(url, "utf-8");
			JSONObject json = JSONObject.fromObject(result);
			if (json.getInt("status") != 0) {
				System.out.println(json.getString("msg"));
			} else {
				JSONArray resultarr = json.optJSONArray("result");
				for (int i = 0; i < resultarr.size(); i++) {
					JSONObject obj = (JSONObject) resultarr.opt(i);
					String title = obj.getString("title");
					String year = obj.getString("year");
					String month = obj.getString("month");
					String day = obj.getString("day");
					String content = obj.getString("content");
					System.out.println(title + " " + year + " " + month + " " + day + " " + content);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}