z這裏用百度地圖的逆地理編碼接口爲例,html
第一種方式:(經過jdk中的java.net包)java
import java.net.URL; import java.net.URLConnection;
String url = "http://api.map.baidu.com/geocoder/v2/?" + "callback=renderReverse&location=40.073357,116.352891&output=json&pois=0&ak=" + mapAk;
URL myURL = null; URLConnection httpsConn = null; myURL = new URL(url); httpsConn = (URLConnection) myURL.openConnection();
InputStreamReader insr = null; insr = new InputStreamReader( httpsConn.getInputStream(), "UTF-8"); BufferedReader br = new BufferedReader(insr); String dataStr = br.readLine();
insr.close();
第二種方式:(經過httpclient實現)json
明天整理,參考以下(可點擊外鏈)api
http://www.javashuo.com/article/p-xkkqcuky-b.html工具
最後獲得一個json的字符串,而咱們須要拿到其中某個key對應的value,因此就須要對json串進行解析編碼