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); Traitable fileTraited = new Traitable(jsonReader);
HashMap<String, Object> allVariables = fileTraited.getVariableMap(); HashMap<String, Object> allVariables = fileTraited.getVariableMap();
for (String key : allVariables.keySet()) {
System.out.println("Clé : " + key + " , Valeur : " + allVariables.get(key));
}
jsonReader.close(); jsonReader.close();
} catch (IOException e) { } catch (IOException e) {
System.out.println("[!] Fichier " + url.getFile() + " n'existe pas"); System.out.println("[!] Fichier " + url.getFile() + " n'existe pas");

View File

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

View File

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