:
package com.idc.dataaudit.dataresource; import java.util.arraylist; import java.util.hashmap; import java.util.iterator; import java.util.list; import java.util.map; import net.sf.json.jsonArray; import net.sf.json.jsonobject; import; org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.httpmethod; import org.apache.commons.httpclient.methods.getMethod; public class demandehttpmanage {String Results <Integer, string> requesththtpinfo (String Url) null; map <nteger, string> mapResult = new HashMap <Integer, String> (); essayez {httpClient client = new httpClient (); HttpMethod Method = new GetMethod (URL); // 使用 Post 方法 // HttpMethod Method = new PostMethod ("http://java.sun.com"); client.executeMethod (méthode); // 打印服务器返回的状态 //System.out.println(Method.getProtoColVersion ()); // System.out.println (Method.getStatusline (). GetStatuscode ()); // System.out.println (Method.getSatusline (). GetReasonPhrase ()); // System.out.println (méthode.getStatusline (). ToString ()); // System.out.println (méthode.getStatusline ()); // 打印返回的信息 // System.out.println (méthode.getResponseBodyAsstring ()); MapResult.put (méthode.getStatusline (). getStaturcode (), méthode.getResponseBodyAsstring ()); // 释放连接 Method.reeleaseconnection (); } catch (exception e) {e.printStackTrace (); } System.out.println (MapResult); retour MapResult; } public map <string, list <string>> getMapFromJSon (String jsonstr) {map <string, list <string>> mapResult = new hashmap <string, list <string>> (); try {jsonObject result = jsonObject.fromObject (jsonstr); // 转换为 jsonObject jSonArray namelist = result.getJSonArray ("result"); // 获取 jsonArray int length = namelist.size (); for (int i = 0; i <length; i ++) {jsonObject tempObject = namelist.getjsonObject (i); Iterator iter = tempObject.Keys (); String key = (string) iter.next (); String keyId = tempObject .getString (key); List <string> objList = new ArrayList <string> (); for (; iter.hasnext ();) {String keyLocal = (string) iter.next (); // System.out.println (key + "=" + tempObject .getString (keyLocal)); objList.add (tempObject .getString (keyLocal)); } mapResult.put (keyId, objList); }} catch (exception e) {e.printStackTrace (); } System.out.println (MapResult); retour MapResult; }}以上就是小编为大家带来的 httpclient 请求 http 数据, json 转 map 的实例全部内容了 , 希望大家多多支持武林网 ~