ÃֽŠ°Ô½Ã±Û(JAVA) HOME > JAVA > ÃֽŠ°Ô½Ã±Û(JAVA) 2019.05.29 / 24:22 Java·Î open api jsonÆÄ½Ì Å¹µ¹ÀÌ°³¹ßÀÚ Ãßõ ¼ö 224 ¼¿ï½Ã °íµîÇб³ ÇöȲ Ãâ·ÂÀÎÁõÅ° ½ÅûÀÎÁõÅ°¸¦ ½ÅûÇÏ°í ³ª¼ ÀÎÁõÅ° È®Àοäû URL¿äû ÀÎÀÚÃâ·Â°ª¿äû µ¥ÀÌÅÍjson_simple ¶óÀ̺귯¸® Ãß°¡package high; import java.io.BufferedInputStream;import java.net.URL; import org.json.simple.JSONArray;import org.json.simple.JSONObject;import org.json.simple.parser.JSONParser; public class HighSchool { static String key = "537047574c726f723130377964455344"; public HighSchool() throws Exception{ JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject)jsonParser.parse(readUrl()); JSONObject json = (JSONObject)jsonObject.get("SchulInfoHgschl"); JSONArray array = (JSONArray)json.get("row"); for(int i=0; i<array.size(); i++){ JSONObject row = (JSONObject)array.get(i); String school = (String)row.get("SCHUL_NM"); System.out.println(school); } } private static String readUrl() throws Exception{ BufferedInputStream reader = null; try { URL url = new URL("http://openapi.seoul.go.kr:8088/" + key+"/json/SchulInfoHgschl/1/20/"); reader = new BufferedInputStream(url.openStream()); StringBuffer buffer = new StringBuffer(); int i = 0; byte[] b = new byte[4096]; while((i = reader.read(b)) != -1){ buffer.append(new String(b, 0, i)); } return buffer.toString(); } finally{ if(reader != null) reader.close(); } }} Colored by Color Scriptermainpackage high; public class main { public static void main(String[] args) throws Exception { HighSchool school = new HighSchool(); } } Colored by Color Scripter½ÇÇà[Ãâó] Java·Î open api jsonÆĽÌ|ÀÛ¼ºÀÚ minjara < Prev 5. Java·Î ±â»óû API JSONÀ¸·Î ÆĽÌÇϱ⠴ÙÀ½ ¸Ê API(Ä«Ä«¿À ¸Ê) ¶óÀÎ ±×¸®±â, ¶óÀÎ °Å¸® ±¸Çϱâ Next > ¢¾ Ãßõ ¸ñ·Ï