importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.net.HttpURLConnection;importjava.net.Malformed...
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class Test_1 {
private static String result = "";
public static void main(String[] args) {
URL url;
try {
url = new URL(
"http://v.juhe.cn/postcode/pcd?dtype=json&key=9da227adffff9ae94536d73c298651fc");
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection();
urlcon.connect(); // 获取连接
InputStream is = urlcon.getInputStream();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(is));
StringBuffer bs = new StringBuffer();
String linputline = null;
while ((linputline = buffer.readLine()) != null) {
result += linputline + "\n";
}
System.out.println(result);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
///{"reason":"successed","result":[{"id":"1","province":"涓婃捣甯?,"city":[{"id":"32","city":"涓婃捣甯?,"
展开