java訪問url介面,返回json字串
阿新 • • 發佈:2020-12-15
public static String loadJSON (String url) { StringBuilder json = new StringBuilder(); try { URL oracle = new URL(url); URLConnection yc = oracle.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine = null; while ( (inputLine = in.readLine()) != null ) { json.append(inputLine); } in.close(); } catch(MalformedURLException e) { } catch(IOException e) { } return json.toString(); } }