首页 车辆尾号限行 车辆尾号限行示例代码 城市限行查询[Java]

城市限行查询示例代码[Java]

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

城市限行查询

package api.jisuapi.vehiclelimit;

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/vehiclelimit/query";
	public static final String city = "hangzhou";// 城市
	public static final String date = "2015-12-02";// 时间

	public static void Get() {
		String result = null;
		String url = URL + "?appkey=" + APPKEY + "&city=" + city + "&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 city = resultarr.getString("city");
				String cityname = resultarr.getString("cityname");
				String date = resultarr.getString("date");
				String week = resultarr.getString("week");
				String area = resultarr.getString("area");
				String summary = resultarr.getString("summary");
				String numberrule = resultarr.getString("numberrule");
				String number = resultarr.getString("number");
				System.out.println(city + " " + cityname + " " + date + " " + week + " " + area + " " + summary + " "
						+ numberrule + " " + number);
				JSONArray time = resultarr.optJSONArray("time");
				for (int i = 0; i < time.size(); i++) {
					System.out.println(time.get(i));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}