android的app没有不联网的基本上现在,经常会有与服务器的交互这个时候,会遇到很多解析服务器返回的数据这个简单的函数就是干这个的
1 static public String Change(HttpResponse httpResponce) { 2 String result = null; 3 try { 4 BufferedReader bufferedReader = new BufferedReader( 5 new InputStreamReader(httpResponce.getEntity().getContent())); 6 StringBuffer stringBuffer = new StringBuffer(""); 7 // 获取本系统的行分割线 8 String NL = System.getProperty("line.separator"); 9 // 把http响应的输入流数据按行读取到StringBuffer中 10 String line = ""; 11 while ((line = bufferedReader.readLine()) != null) { 12 stringBuffer.append(line + NL); 13 } 14 result = stringBuffer.toString(); 15 } catch (IllegalStateException e) { 16 // TODO Auto-generated catch block 17 e.printStackTrace(); 18 } catch (IOException e) { 19 // TODO Auto-generated catch block 20 e.printStackTrace(); 21 } 22 System.out.println("the result is " + result); 23 return result; 24 }