How to maintain the order of a JSONObject

后端 未结 12 1629
栀梦
栀梦 2020-12-11 05:49

I am using a JSONObject in order to remove a certin attribute I don\'t need in a JSON String:

JSONObject jsonObject = new JSONObject(jsonString);
jsonObject.         


        
12条回答
  •  旧时难觅i
    2020-12-11 06:24

    Go on JSONObject class Change from HashMap() to LinkedHashMap()

     /**
         * Construct an empty JSONObject.
         */
        public JSONObject() {
            this.map = new LinkedHashMap();
        }
    

    The LinkedHashMap class extends the Hashmap class. This class uses a doubly linked list containing all the entries of the hashed table, in the order in which the keys were inserted in the table: this allows the keys to be "ordered".

提交回复
热议问题