package api.jisuapi.transit;
import java.net.URLEncoder;
import api.util.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Station {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "https://api.jisuapi.com/transit/station";
public static final int cityid = 382;// 杭州
public static final String station = "西溪竞舟苑";// utf-8
public static void Get() throws Exception {
String result = null;
String url = URL + "?cityid=" + cityid + "&station=" + URLEncoder.encode(station, "utf-8") + "&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 {
JSONArray resultarr = json.optJSONArray("result");
for (int i = 0; i < resultarr.size(); i++) {
JSONObject data = (JSONObject) resultarr.opt(i);
String transitno = data.getString("transitno");
String startstation = data.getString("startstation");
String endstation = data.getString("endstation");
System.out.println(transitno + " " + startstation + " " + endstation);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Java HTTP请求通用函数
Java Android请求通用函数


© 2015-2025 杭州极速互联科技有限公司 版权所有 浙ICP备17047587号-4 浙公网安备33010502005096 增值电信业务经营许可证:浙B2-20190875