1 /** 2 * 根据传入url请求,返回json字符串 3 * @param url 4 * @return 5 * @throws UnsupportedEncodingException 6 */ 7 public static String loadJSON(String url) throws UnsupportedEncodingException { 8 StringBuilder json = new StringBuilder(); 9 try { 10 11 URL tempurl = new URL(url); 12 URLConnection conn = tempurl.openConnection(); 13 14 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8")); 15 String inputLine = null; 16 while ((inputLine = in.readLine()) != null) { 17 json.append(inputLine); 18 } 19 20 in.close(); 21 } catch (MalformedURLException e) { 22 e.printStackTrace(); 23 } catch (IOException e) { 24 e.printStackTrace(); 25 } 26 return json.toString(); 27 }