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;
}
}