import java.io.BufferedReader;
import java.io.FileReader;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

public class GwangjuBusJsonMain {
	public static void main(String[] args) {
		String jsonData = getJsonData();
		//System.out.println(jsonData);
		try {
			JSONArray array = JSONArray.fromObject(jsonData);
			for (Object object : array) {
				JSONObject obj = (JSONObject) JSONSerializer.toJSON(object);
				System.out.print("노선이름 : " + obj.get("LINE_NAME") + "\t");
				System.out.print("출발지 : " + obj.get("DIR_UP_NAME") + "\t");
				System.out.print("도착지 : " + obj.get("DIR_DOWN_NAME") + "\n\n");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	//gjbus.json 파일의 내용을 읽어서, JSON 구조 형태로 만들어 준다.
	public static String getJsonData() {
		String json = null;
		String jsonData = "";
		try {
			FileReader fr = new FileReader("gjbus.json");
			BufferedReader br = new BufferedReader(fr);
			while(true) {
				json = br.readLine();
				if(json == null) {
					break;
				}else {
					jsonData += json;
				}
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}

'For developer > JAVA' 카테고리의 다른 글

JDBC ORACLE 연결 오류 뜰 시 설정하는 법  (0) 2020.04.23
자바 환경구축  (0) 2020.04.23
(JAVA_jdbc)기본1  (0) 2020.04.22
(Java_Pasrshing)다음 인기검색어 파싱하기  (0) 2020.04.19
(Java_Json)예제  (0) 2020.04.19

+ Recent posts