/**
* @param args
*/
public static void main(String[] args) throws Exception{
URL yahoo = new URL("
http://www.baidu.com/query.jsp?param1=value2¶m2=value2");
URLConnection context = yahoo.openConnection();
context.setRequestProperty("accept", "*/*"); context.setRequestProperty("connection", "Keep-Alive"); context.setRequestProperty("user-agent",sss "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 发送POST以下两行必须设置请求 context.setDoOutput(true); context.setDoInput(true); // 获取URLConnection对应对象的输出流 out = new PrintWriter(context.getOutputStream()); // 发送请求参数 // out.print(param); // flush缓冲输出流 out.flush();
InputStream br = context.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(br, "utf-8")); String inputLine; String json =""; while ((inputLine = in.readLine()) != null) json =inputLine;// System.out.println(inputLine); in.close();
System.out.println(json);
JSONObject jsStr = JSONObject.fromObject(json);
JSONArray jsar = JSONArray.fromObject(jsStr.getString("kaoHY")); List<Map> list = (List<Map>) jsar.toCollection(jsar, Map.class); for(Map employee : list){ System.out.println(employee.get("ZJBM")); } }