根据传入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();
}

posted on 2017-06-06 08:19  Holyz  阅读(121)  评论(0编辑  收藏  举报