public class Test1111 {
public static void main(String[] args) throws Exception {
//这里写你要访问的url地址
String url = "www.baidu.com";
//参数
String param1 ="liu";
String param2 ="youer";
HttpRequest hr = new HttpRequest();//这个类,请看我另外一篇
hr.setURL(url);
//访问方法为post
hr.setMethod("POST");
hr.addParam("xing",param1);
hr.addParam("ming",param2);
String response = hr.Send();
//取值方法如下:
JSONObject ret = JSONObject.fromObject(response);
/**
* 如果是多层的Json,比如
* {"server_response":{"status_code":201,"balance":"1974600.00",""coupons_balance":"0.00"}}
* 具体取值,如下:
* JSONObject jsonObj = JSONObject.fromObject(response);
JSONObject jsonObj1 =jsonObj.getJSONObject("server_response");
Object balance =jsonObj1.get("balance");
Object coupons_balance =jsonObj1.get("coupons_balance");
* */
}
}
public static void main(String[] args) throws Exception {
//这里写你要访问的url地址
String url = "www.baidu.com";
//参数
String param1 ="liu";
String param2 ="youer";
HttpRequest hr = new HttpRequest();//这个类,请看我另外一篇
hr.setURL(url);
//访问方法为post
hr.setMethod("POST");
hr.addParam("xing",param1);
hr.addParam("ming",param2);
hr.addParam("sex","男");
String response = hr.Send();
//取值方法如下:
JSONObject ret = JSONObject.fromObject(response);
/**
* 如果是多层的Json,比如
* {"server_response":{"status_code":201,"balance":"1974600.00",""coupons_balance":"0.00"}}
* 具体取值,如下:
* JSONObject jsonObj = JSONObject.fromObject(response);
JSONObject jsonObj1 =jsonObj.getJSONObject("server_response");
Object balance =jsonObj1.get("balance");
Object coupons_balance =jsonObj1.get("coupons_balance");
* */
}
}