This commit is contained in:
pro.boooooo 2023-01-05 18:34:55 +01:00
parent e6e8925fd2
commit cc6dd53394
5 changed files with 74 additions and 68 deletions

Binary file not shown.

Binary file not shown.

View File

@ -30,6 +30,10 @@ public class GraphicFile extends JPanel {
Traitable fileTraited = new Traitable(jsonReader);
HashMap<String, Object> allVariables = fileTraited.getVariableMap();
for (String key : allVariables.keySet()) {
System.out.println("Clé : " + key + " , Valeur : " + allVariables.get(key));
}
jsonReader.close();
} catch (IOException e) {
System.out.println("[!] Fichier " + url.getFile() + " n'existe pas");

View File

@ -38,6 +38,8 @@ public class Traitable {
allJson.append(c);
}
allJson = this.ajustementVirguleEnd(allJson.toString());
while (i < allJson.length()) {
if (allJson.charAt(i) == '"') {
while (allJson.charAt(i) != ',') {
@ -45,7 +47,38 @@ public class Traitable {
i++;
}
// System.out.println(this.getNomOfRecord(tmp));
Object value = new Object();
String name = this.getNomOfRecord(tmp);
String[] typeOfVariable = this.getValueOfRecord(tmp.toString());
switch (typeOfVariable[0]) {
case "int": {
value = Integer.valueOf(typeOfVariable[1]);
break;
}
case "string": {
value = String.valueOf(typeOfVariable[1]);
break;
}
case "boolean": {
value = Boolean.valueOf(typeOfVariable[1]);
break;
}
case "float": {
value = Double.valueOf(typeOfVariable[1]);
break;
}
default: {
value = null;
break;
}
}
this.content.put(name, value);
tmp.setLength(0);
}
@ -53,7 +86,6 @@ public class Traitable {
}
} catch (StringIndexOutOfBoundsException ignore) {
}
} catch (IOException e) {
System.out.println("[!] Probleme lors de la lecture du fichier");
}
@ -76,80 +108,50 @@ public class Traitable {
return null;
}
// TODO: a finir (Bilal)
private Object getValueOfRecord(StringBuilder sb) {
// int i;
// int counter;
// StringBuilder value = new StringBuilder();
// String type = "";
/**
* Pour recuperer le type et la valeur d'une variable JSON
*
* @param jsonLine La ligne json a evaluer
* @return Un tableau { [0] = type, [1] = valeur }
*/
private String[] getValueOfRecord(String jsonLine) {
String[] parts = jsonLine.split(":");
String value = parts[1];
// /**
// * Tableau
// */
// if (sb.indexOf("[") != -1) {
// type = "tableau";
// }
if (value.charAt(0) == ' ') {
value = value.substring(1);
}
// /**
// * Chaine de characteres
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
if (value.contains("\"")) {
return new String[] { "string", value };
} else if (value.contains("{")) {
return new String[] { "objet", value };
} else if (value.contains("[")) {
return new String[] { "tableau", value };
} else if (value.contains("true") || value.contains("false")) {
return new String[] { "boolean", value };
} else if (value.contains(".")) {
return new String[] { "float", value };
} else {
return new String[] { "int", value };
}
}
// if (counter < 2 && sb.indexOf(".") != -1) {
// type = "float";
// }
private StringBuilder ajustementVirguleEnd(String str) {
int longueur = str.length();
char avantDernierCaractere = str.charAt(longueur - 2);
String nouvelleChaine = str.substring(0, longueur - 2) + avantDernierCaractere + ","
+ str.substring(longueur - 1);
// /*
// * Objet
// */
// if (sb.indexOf("{") != -1) {
// type = "objet";
// }
// /*
// * Integer
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
// if (counter < 2) {
// type = "int";
// }
// /**
// * Flottant
// */
// for (i = 0, counter = 0; i <= sb.length() - 1; i++) {
// if (sb.charAt(i) == '"') {
// counter++;
// }
// }
// if (counter < 2 && sb.indexOf(".") != -1) {
// type = "float";
// }
return null;
return new StringBuilder(nouvelleChaine);
}
/**
* Ajouter le jeu de cle valeur dans la liste
* Recuperer le jeu de cles valeurs dans GrahicFile
*
* @param name Nom de la variable
* @param value Contenue de la variable
* @see Graphics.GraphicFile
* @return Le jeu de cles valeurs
*/
private void addToList(String name, Object value) {
System.out.println("[+] => " + name + ": " + value);
this.content.put(name, value);
}
public HashMap<String, Object> getVariableMap() {
return this.content;
}

View File

@ -1 +1 @@
{"prenom":"Bilal", "age": 19,}
{"prenom":"Bilal", "age": 19, "nationalite": "Franco-Algerienne", "enVie": true, "poid": 1.7}