package api.jisuapi.transit; import java.net.URLEncoder; import api.util.HttpUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class Nearby { public static final String APPKEY = "your_appkey_here";// 你的appkey public static final String URL = "https://api.jisuapi.com/transit/nearby"; public static final String city = "杭州";// utf-8 public static final String address = "西溪竞舟苑";// utf-8 public static void Get() throws Exception { String result = null; String url = URL + "?city=" + URLEncoder.encode(city, "utf-8") + "&address=" + URLEncoder.encode(address, "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 station = data.getString("station"); String lat = data.getString("lat"); String lng = data.getString("lng"); String distance = data.getString("distance"); System.out.println(station + " " + lat + " " + lng + " " + distance); JSONArray lines = data.optJSONArray("lines"); for (int j = 0; j < lines.size(); j++) { System.out.println(lines.get(j)); } } } } catch (Exception e) { e.printStackTrace(); } } }