print json file

This commit is contained in:
Boyeau Indy 2021-05-31 18:37:02 +00:00
parent a069067c9c
commit 8d5d19dffd

View File

@ -1,22 +1,54 @@
package configuration; package configuration;
//import java.io.*; import java.io.*;
//import org.json.simple.JSONObject; import org.json.simple.*;
//import org.json.simple.parser.JSONParser; import org.json.simple.parser.*;
//import org.json.simple.parser.ParseException;
//public class JsonToJava { public class JsonToJava {
// public static void main(String args[]) {
// JSONParser jsonP = new JSONParser(); public static void main(String args[]) {
// try {
// JSONObject jsonO = (JSONObject)jsonP.parse(new FileReader("src/configuration/config.json")); // initialize the parser
// String test = (String) jsonO.get("test"); JSONParser jsonP = new JSONParser();
// System.out.println("Name :"+ test); try {
// } catch (FileNotFoundException e) { // read the json document
// e.printStackTrace(); JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("src/configuration/config.json"));
// } catch (IOException e) {
// e.printStackTrace(); //to print all values
// } catch (ParseException e) { //System.out.println(jsonO.values());
// e.printStackTrace();
// } // isolate the "test" part and print it
// } // String test = (String) jsonO.get("test");
//} // System.out.println("ceci est un test :" + test);
//select an element on the list
JSONArray arene = (JSONArray) jsonO.get("arena");
//print a case of this element
System.out.println(arene.get(1));
JSONArray nb_players = (JSONArray) jsonO.get("nb_players");
System.out.println(nb_players.get(1));
JSONArray character1 = (JSONArray) jsonO.get("character1");
System.out.println(character1.get(1));
JSONArray character2 = (JSONArray) jsonO.get("character2");
System.out.println(character2.get(1));
JSONArray resolution = (JSONArray) jsonO.get("resolution");
System.out.println(resolution.get(1));
JSONArray button = (JSONArray) jsonO.get("button");
System.out.println(button);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}