Bonjour,
J'ai crée la méthode suivante, et je souhaiterai savoir si cela vous semble logique
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 /** * Méthode permettant de charger un fichier JSON depuis un emplacement * * @param filePath représente le chemin du fichier en entrée * @param fileEncoding représente l'encodage que l'on veut pour ce fichier * @return un objet JSON * @throws FileNotFoundException * @throws IOException * @throws JsonParseException si la chaîne JSON n'a pu être parsée */ public static JSONArray loadJSONFile(String filePath, String fileEncoding) throws FileNotFoundException, IOException, JsonParseException { try { String stringJson = OneConfig.getDirJsonModel(); // Récupérer la chaîne json depuis son emplacement new JsonParser().parse(stringJson); // Instancier un objet JsonParser pour parser le fichier JSONObject entityObj = JSONObject.fromObject(filePath); // convertir notre élément JSON en un objet JSON return entityObj.optJSONArray(filePath); } catch (Exception e) { // TODO } finally { // TODO } return null; }
En effet j'utilise la variable stringJson que je parse avec la méthode statique parse(String) de la classe JsonParser mais ensuite aprés l'instanciation je crée une variable entityObject et je n'utilise plus stringJson qui a été parsé.
Merci d'avance.
Transact.
Partager