package api.jisuapi.unitconvert; import api.util.HttpUtil; import net.sf.json.JSONObject; public class Unit { public static final String APPKEY = "your_appkey_here";// 你的appkey public static final String URL = "https://api.jisuapi.com/unitconvert/unit"; public static void Get() { String result = null; String url = URL + "?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"); if (resultarr.opt("length") != null) { JSONObject list = resultarr.optJSONObject("length"); if (list.opt("光年") != null) { JSONObject guang = list.optJSONObject("光年"); String ename1 = guang.getString("ename"); String symbol = guang.getString("symbol"); String ratio = guang.getString("ratio"); System.out.println(ename1 + " " + symbol + " " + ratio); } if (list.opt("天文单位") != null) { JSONObject tian = list.optJSONObject("天文单位"); String ename1 = tian.getString("ename"); String symbol = tian.getString("symbol"); String ratio = tian.getString("ratio"); System.out.println(ename1 + " " + symbol + " " + ratio); } if (list.opt("千米") != null) { JSONObject qian = list.optJSONObject("千米"); String ename1 = qian.getString("ename"); String symbol = qian.getString("symbol"); String ratio = qian.getString("ratio"); String alias = qian.getString("alias"); System.out.println(ename1 + " " + symbol + " " + ratio + " " + alias); } if (list.opt("米") != null) { JSONObject mi = list.optJSONObject("米"); String ename1 = mi.getString("ename"); String symbol = mi.getString("symbol"); String ratio = mi.getString("ratio"); String isSI = mi.getString("isSI"); System.out.println(ename1 + " " + symbol + " " + ratio + " " + isSI); } } if (resultarr.opt("area") != null) { JSONObject area = resultarr.optJSONObject("area"); if (area.opt("平方千米") != null) { JSONObject ping = area.optJSONObject("平方千米"); String ename1 = ping.getString("ename"); String symbol = ping.getString("symbol"); String ratio = ping.getString("ratio"); System.out.println(ename1 + " " + symbol + " " + ratio); } if (area.opt("公顷") != null) { JSONObject gong = area.optJSONObject("公顷"); String ename1 = gong.getString("ename"); String symbol = gong.getString("symbol"); String ratio = gong.getString("ratio"); System.out.println(ename1 + " " + symbol + " " + ratio); } if (area.opt("平方米") != null) { JSONObject ping = area.optJSONObject("平方米"); String ename1 = ping.getString("ename"); String symbol = ping.getString("symbol"); String ratio = ping.getString("ratio"); String isSI = ping.getString("isSI"); System.out.println(ename1 + " " + symbol + " " + ratio + " " + isSI); } if (area.opt("公亩") != null) { JSONObject mu = area.optJSONObject("公亩"); String ename1 = mu.getString("ename"); String symbol = mu.getString("symbol"); String ratio = mu.getString("ratio"); System.out.println(ename1 + " " + symbol + " " + ratio); } } } } catch (Exception e) { e.printStackTrace(); } } }
© 2015-2024 杭州极速互联科技有限公司 版权所有 浙ICP备17047587号-4 浙公网安备33010502005096 增值电信业务经营许可证:浙B2-20190875