首页 > 解决方案 > 我在输出 JsonFile 中的键以相反的顺序显示

问题描述

我正在使用一种方法来显示包含一些信息和键值的 JsonArray,但是该方法在键之前显示数组,而我想要相反。有人能告诉我我的错误在哪里吗?我的方法是:

    @SuppressWarnings("unchecked")
public void ecrireFichierJSon(String fichierSortie) {

    org.json.simple.JSONObject completOrNot = new org.json.simple.JSONObject();
    if (mssgErreurResult().isEmpty()) {
        completOrNot.put("complet", true);
    } else {
        completOrNot.put("complet", false);
    }

    org.json.simple.JSONArray messagesErreur = new org.json.simple.JSONArray();
    messagesErreur.addAll(mssgErreurResult());

    completOrNot.put("erreurs", messagesErreur);

    org.json.simple.JSONArray erreurList = new org.json.simple.JSONArray();
    erreurList.add(completOrNot);

    try {
        Files.write(Paths.get(fichierSortie), completOrNot.toJSONString().getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
}

这是输出文件:

{"erreurs":["Errors..."],"complet":false}

标签: javaarraysjsonfiledependencies

解决方案


推荐阅读