基于php的地铁查询系统,公交地铁查询

package api.jisuapi.transit;

import java.net.URLEncoder;

import api.util.HttpUtil;

import net.sf.json.JSONArray;

import net.sf.json.JSONObject;

public class Station2s {

public static final String APPKEY = "your_appkey_here";// 你的appkey

public static final String URL = "https://api.jisuapi.com/transit/station2s";

public static final String city = "杭州";// utf-8

public static final String start = "西溪竞舟苑";// utf-8

public static final String end = "杭州汽车北站";// utf-8

public static final String type = "";

public static void Get() throws Exception {

String result = null;

String url = URL + "?city=" + URLEncoder.encode(city, "utf-8") + "&start=" + URLEncoder.encode(start, "utf-8")

+ "&end" + URLEncoder.encode(end, "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 totaldistance = data.getString("totaldistance");

String totalduration = data.getString("totalduration");

String totalprice = data.getString("totalprice");

String arrivetime = data.getString("arrivetime");

String tiptype = data.getString("tiptype");

String totalstopnum = data.getString("totalstopnum");

String totalwalkdistance = data.getString("totalwalkdistance");

String vehicles = data.getString("vehicles");

System.out.println(totaldistance + " " + totalduration + " " + totalprice + " " + arrivetime + " "

+ tiptype + " " + totalstopnum + "" + totalwalkdistance + " " + vehicles);

if (data.opt("steps") != null) {

JSONArray step = data.optJSONArray("steps");

for (int j = 0; j < step.size(); j++) {

JSONObject steps = (JSONObject) step.opt(j);

String distance = steps.getString("distance");

String duration = steps.getString("duration");

String sname = "";

if (steps.has("sname")) {

sname = steps.getString("sname");

}

String type = steps.getString("type");

String vehicle = steps.getString("vehicle");

String startpoi = steps.getString("startpoi");

String endpoi = steps.getString("endpoi");

String steptext = steps.getString("steptext");

String endname = "";

if (steps.has("endname")) {

endname = steps.getString("endname");

}

System.out.println(distance + " " + duration + " " + sname + " " + type + " " + vehicle

+ " " + startpoi + " " + endpoi + " " + steptext + " " + endname);

}

}

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值