package api.jisuapi.unitconvert;
import .URLEncoder;
import api.util.HttpUtil;
import net.sf.json.JSONObject;
public class Convert {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "/unitconvert/convert";
public static final String from = "千米";// utf-8
public static final String to = "米";// utf-8
public static final String amount = "5";
public static void Get() throws Exception {
String result = null;
String url = URL + "?appkey=" + APPKEY + "&from=" + URLEncoder.encode(from, "utf-8") + "&to="
+ URLEncoder.encode(to, "utf-8") + "&amount=" + amount;
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 from = resultarr.getString("from");
String to = resultarr.getString("to");
String fromename = resultarr.getString("fromename");
String toename = resultarr.getString("toename");
String fromsymbol = resultarr.getString("fromsymbol");
String tosymbol = resultarr.getString("tosymbol");
String rate = resultarr.getString("rate");
String camount = resultarr.getString("camount");
System.out.println(from + " " + to + " " + fromename + " " + toename + " " + fromsymbol + " " + tosymbol
+ " " + rate + " " + camount);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}