查身份证归属地的,想用swing 写个图像化得查询界面,大家帮忙指导下呗

aw254355 发布于 2016/12/11 20:24
阅读 155
收藏 0
public class Demo {


public static void main(String [] args) {
String httpUrl = "http://apis.baidu.com/apistore/idservice/id";
System.out.println("请你输入身份证号码:");
System.out.println("例如输入:id=412827198512032731");
Scanner in=new Scanner(System.in);
String  str=in.nextLine();
String httpArg = str;
String jsonResult = request(httpUrl, httpArg);
//System.out.println(jsonResult);
try {
JSONObject  jsonobject =new JSONObject(jsonResult);
JSONObject JsonRetdate=jsonobject.getJSONObject("retData");
String  address=JsonRetdate.getString("address");
System.out.println("地址:"+address);
String sex=JsonRetdate.getString("sex");
System.out.println("性别:"+sex);
String birthday=JsonRetdate.getString("birthday");
System.out.println("出生年月:"+birthday);

} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}










/**
* @param urlAll
*            :请求接口
* @param httpArg
*            :参数
* @return 返回结果
*/
public static  String request(String httpUrl, String httpArg) {
   BufferedReader reader = null;
   String result = null;
   StringBuffer sbf = new StringBuffer();
   httpUrl = httpUrl + "?" + httpArg;


   try {
       URL url = new URL(httpUrl);
       HttpURLConnection connection = (HttpURLConnection) url
               .openConnection();
       connection.setRequestMethod("GET");
       // 填入apikey到HTTP header
       connection.setRequestProperty("apikey",  "e9177c9469255709868b4832a3ddeeb4");
       connection.connect();
       InputStream is = connection.getInputStream();
       reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
       String strRead = null;
       while ((strRead = reader.readLine()) != null) {
           sbf.append(strRead);
           sbf.append("\r\n");
       }
       reader.close();
       result = sbf.toString();
   } catch (Exception e) {
       e.printStackTrace();
   }
   return result;
}




}
加载中
0
红薯官方
红薯官方

下载安装一个NetBeans ,就可以使用“拖控件” 就像堆垃圾一样堆出Swing的UI来,太简单了。

界面归界面,逻辑设计在业务层。

很简单的。