📜  如何从 web api java 代码示例中读取 .json

📅  最后修改于: 2022-03-11 14:52:43.406000             🧑  作者: Mango

代码示例1
try {
            URL url = new URL("url");
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setRequestMethod("GET");
            conn.connect();
            if(conn.getResponseCode() == 200) {
                Scanner scan = new Scanner(url.openStream());
                while(scan.hasNext()) {
                    String temp = scan.nextLine();
                      //parse json here
                }
            }
}