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

mac2022-06-30  125

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

转载于:https://www.cnblogs.com/bilaisheng/p/10211054.html

最新回复(0)