Created
November 16, 2017 14:08
-
-
Save hiroto3432/fa08051830bbc5d75f5731392b1c1fe8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.json.JSONObject; | |
import org.json.JSONArray; | |
import processing.core.PApplet; | |
import java.io.*; | |
import java.util.ArrayList; | |
public class Jsontest{ | |
public static ArrayList<Subject> sub = new ArrayList<>(); | |
public static void main(String[] args) throws NullPointerException{ | |
String data = readFile(); | |
JSONArray JArray = new JSONArray(data); | |
for(int n=0; n<JArray.length(); n++) { | |
JSONObject Jobject = JArray.getJSONObject(n); | |
String name = (String)Jobject.get("name"); | |
String day = (String)Jobject.get("day"); | |
float fperiod = Float.valueOf(Jobject.get("period").toString()); | |
int period = (int)fperiod; | |
sub.add(new Subject(name , day, period)); | |
} | |
PApplet.main("GUIbyP5"); | |
} | |
public static class Subject{ | |
String name; | |
int day; | |
int period; | |
Subject(String name,String day,int period){ | |
this.name = name; | |
this.period = period; | |
switch(day){ | |
case "Mon": this.day = 1; break; | |
case "Tue": this.day = 2; break; | |
case "Wed": this.day = 3; break; | |
case "Thu": this.day = 4; break; | |
case "Fri": this.day = 5; break; | |
} | |
} | |
} | |
private static String readFile(){ | |
try{ | |
File file = new File("src/TimeTable.json"); | |
BufferedReader br = new BufferedReader(new FileReader(file)); | |
String data = ""; | |
String str = br.readLine(); | |
while(str != null){ | |
data += str; | |
str = br.readLine(); | |
} | |
br.close(); | |
return data; | |
}catch(FileNotFoundException e){ | |
System.out.println(e); | |
return null; | |
}catch(IOException e){ | |
System.out.println(e); | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment