请求Json数据

String url ="http://www.imooc.com/api/teacher?type=4&num=50";

StringBuffer sb=new StringBuffer();

String line=null;

BufferedReader br =null;

try{

Url=new URL(url);

connection= (HttpURLConnection)Url.openConnection();

br=new BufferedReader(new InputStreamReader(connection.getInputStream()));

while((line=br.readLine())!=null){

sb.append(line);

}

}catch(Exception e) {

e.printStackTrace();

}

finally{

try{

br.close();

}catch(IOException e) {

e.printStackTrace();

}

}

returnsb.toString();

你可能感兴趣的:(请求Json数据)