print json file
This commit is contained in:
parent
a069067c9c
commit
8d5d19dffd
@ -1,22 +1,54 @@
|
||||
package configuration;
|
||||
|
||||
//import java.io.*;
|
||||
//import org.json.simple.JSONObject;
|
||||
//import org.json.simple.parser.JSONParser;
|
||||
//import org.json.simple.parser.ParseException;
|
||||
//public class JsonToJava {
|
||||
// public static void main(String args[]) {
|
||||
// JSONParser jsonP = new JSONParser();
|
||||
// try {
|
||||
// JSONObject jsonO = (JSONObject)jsonP.parse(new FileReader("src/configuration/config.json"));
|
||||
import java.io.*;
|
||||
import org.json.simple.*;
|
||||
import org.json.simple.parser.*;
|
||||
|
||||
public class JsonToJava {
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
// initialize the parser
|
||||
JSONParser jsonP = new JSONParser();
|
||||
try {
|
||||
// read the json document
|
||||
JSONObject jsonO = (JSONObject) jsonP.parse(new FileReader("src/configuration/config.json"));
|
||||
|
||||
//to print all values
|
||||
//System.out.println(jsonO.values());
|
||||
|
||||
// isolate the "test" part and print it
|
||||
// String test = (String) jsonO.get("test");
|
||||
// System.out.println("Name :"+ test);
|
||||
// } catch (FileNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
// 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user