首页 电视节目预告 电视节目预告示例代码 电视节目查询[Java]

电视节目查询示例代码[Java]

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

电视节目查询

package api.jisuapi.tv;

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/tv/query";
	public static final int tvid = 435;
	public static final String date = "2015-10-19";

	public static void Get() {
		String result = null;
		String url = URL + "?appkey=" + APPKEY + "&tvid=" + tvid + "&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 tvid = resultarr.getString("tvid");
				String name = resultarr.getString("name");
				String date = resultarr.getString("date");
				System.out.println(tvid + " " + name + " " + date);
				if (resultarr.opt("program") != null) {
					JSONArray program = resultarr.optJSONArray("program");
					for (int i = 0; i < program.size(); i++) {
						JSONObject obj = (JSONObject) program.opt(i);
						String name_ = obj.getString("name");
						String starttime = obj.getString("starttime");
						System.out.println(name_ + " " + starttime);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}