package api.jisuapi.exchange; import api.util.HttpUtil; import net.sf.json.JSONObject; public class Single { public static final String APPKEY = "your_appkey_here";// 你的appkey public static final String URL = "https://api.jisuapi.com/exchange/single"; public static final String currency = "CNY"; public static void Get() { String result = null; String url = URL + "?currency=" + currency + "&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 { JSONObject resultarr = json.optJSONObject("result"); String currency = resultarr.getString("currency"); String name = resultarr.getString("name"); System.out.println(currency + " " + name); if (resultarr.opt("list") != null) { JSONObject list = resultarr.optJSONObject("list"); if (list.opt("HKD") != null) { JSONObject HKD = (JSONObject) list.opt("HKD"); String name1 = HKD.getString("name"); String rate = HKD.getString("rate"); String updatetime = HKD.getString("updatetime"); System.out.println(name1 + " " + rate + " " + updatetime); } if (list.opt("EUR") != null) { JSONObject EUR = list.optJSONObject("EUR"); String name1 = EUR.getString("name"); String rate = EUR.getString("rate"); String updatetime = EUR.getString("updatetime"); System.out.println(name1 + " " + rate + " " + updatetime); } if (list.opt("HKD") != null) { JSONObject HKD = list.optJSONObject("HKD"); String name1 = HKD.getString("name"); String rate = HKD.getString("rate"); String updatetime = HKD.getString("updatetime"); System.out.println(name1 + " " + rate + " " + updatetime); } } } } catch (Exception e) { e.printStackTrace(); } } }