根据传入url请求,返回json字符串

/**
* 根据传入url请求,返回json字符串
* @param url
* @return
* @throws UnsupportedEncodingException 
*/
public static String loadJSON(String url) throws UnsupportedEncodingException {
StringBuilder json = new StringBuilder();
  try {

    URL tempurl = new URL(url);
    URLConnection conn = tempurl.openConnection();

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
    String inputLine = null;
    while ((inputLine = in.readLine()) != null) {
      json.append(inputLine);
    }

     in.close();
  } catch (MalformedURLException e) {
     e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  return json.toString();
}
上一篇:如何对磁盘做完整的全盘镜像备份?


下一篇:为大连服务外包插上“云计算”翅膀