12306 查询接口 php,火车查询API接口_免费数据接口 - 极速数据

package api.jisuapi.train;

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/train/station2s";

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

public static final String end = "北京";// utf-8

public static final int ishigh = 0;

public static void Get() throws Exception {

String result = null;

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

+ URLEncoder.encode(end, "utf-8") + "&ishigh=" + ishigh;

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 obj = (JSONObject) resultarr.opt(i);

String trainno = obj.getString("trainno");

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

String station = obj.getString("station");

String endstation = obj.getString("endstation");

String departuretime = obj.getString("departuretime");

String arrivaltime = obj.getString("arrivaltime");

String sequenceno = obj.getString("sequenceno");

String costtime = obj.getString("costtime");

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

String isend = obj.getString("isend");

String pricesw = obj.getString("pricesw");

String pricetd = obj.getString("pricetd");

String pricegr1 = obj.getString("pricegr1");

String pricegr2 = obj.getString("pricegr2");

String pricerw1 = obj.getString("pricerw1");

String pricerw2 = obj.getString("pricerw2");

String priceyw1 = obj.getString("priceyw1");

String priceyw2 = obj.getString("priceyw2");

String priceyw3 = obj.getString("priceyw3");

String priceyd = obj.getString("priceyd");

String priceed = obj.getString("priceed");

String pricerz = "";

if (obj.has("pricerz")) {

pricerz = obj.getString("pricerz");

}

String priceyz = "";

if (obj.has("priceyz")) {

priceyz = obj.getString("priceyz");

}

System.out.println(trainno + " " + type + " " + station + " " + endstation + " " + departuretime

+ " " + arrivaltime + " " + sequenceno + " " + costtime + " " + distance + " " + isend + " "

+ pricesw + " " + pricetd + " " + pricegr1 + " " + pricegr2 + " " + pricerw1 + " "

+ pricerw2 + " " + priceyw1 + " " + priceyw2 + " " + priceyw3 + " " + priceyd + " "

+ priceed + " " + pricerz + " " + priceyz);

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值