import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Test {
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
//读
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine = null;
//一行一行读
while ( (inputLine = in.readLine()) != null) {
//追加进json
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
public static void main(String[] args){
String url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=138****1655";
System.out.println(a);
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class Test {
public static String loadJSON (String url) {
StringBuilder json = new StringBuilder();
try {
URL oracle = new URL(url);
URLConnection yc = oracle.openConnection();
//读
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine = null;
//一行一行读
while ( (inputLine = in.readLine()) != null) {
//追加进json
json.append(inputLine);
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return json.toString();
}
public static void main(String[] args){
String url = "https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=138****1655";
String json = loadJSON(url);
//先把得到的字符串分割为数组
String [] st = json.split(",");
//取到地址的下标
String province = st[1];
//通过下标截取出地址
String a= province.substring(province.indexOf("'")+1,province.lastIndexOf("'"));System.out.println(a);
}
}
//输出结果 : 湖北