ÃֽŠ°Ô½Ã±Û(JAVA)
2019.05.29 / 24:22

Java·Î open api jsonÆĽÌ

Źµ¹ÀÌ°³¹ßÀÚ
Ãßõ ¼ö 225
¼­¿ï½Ã °íµîÇб³ ÇöȲ Ãâ·Â

ÀÎÁõÅ° ½Åû


ÀÎÁõÅ°¸¦ ½ÅûÇÏ°í ³ª¼­ ÀÎÁõÅ° È®ÀÎ


¿äû 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 Scripter

main

package 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