Bonjour,

J'ai le message suivant lors du parsing d'un fichier json
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
javax.servlet.ServletException: A JSONObject text must begin with '{' at character 1 of /C:/neuros_distribution/rony/projets/target/1-one-1.9.9/WEB-INF/classes/dynamic/model/json/poste.json
alors que le fichier json passe bien le validateur json
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
{
    "entity": "poste",
    "columns": [
        {"header":"Code", "property":"code"},
        {"header":"Libellé", "property":"lib"},
        {"header":"Unité travail (UT)", "property":"uniteTravail"},
        {"header":"Site", "property":"site"}                  
    ]
}
Voici le code que j'ai conçu pour parser le fichier.
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
27
28
29
 
public class FileReaderUtil {
 
    private static JSONObject entityObj;
    private static String stringJson;
 
    /**
     * 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 JSONObject loadJSONFile(String filePath, String fileEncoding) throws FileNotFoundException, IOException, JsonParseException {
        try {
            stringJson = OneConfig.getDirJsonModel() + filePath; // récupérer la chaîne json depuis son emplacement   
            entityObj = JSONObject.fromObject(new JsonParser().parse(stringJson)); // convertir notre élément JSON en un objet JSON 
 
            return entityObj.getJSONObject(filePath); // on retourne les valeurs de l'objet JSON dans un tableau JSON
 
        } catch (JsonSyntaxException e) {
            System.out.println("Le fichier " + filePath + " a rencontré l'erreur suivante : " + e.getMessage());
        }
        return null;
    }
}

Merci d'avance.
Transact