diff --git a/JSONObject.java b/JSONObject.java index 5ca5a45bc..a30e66d0f 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -38,6 +38,8 @@ of this software and associated documentation files (the "Software"), to deal import java.util.Map; import java.util.ResourceBundle; import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; /** * A JSONObject is an unordered collection of name/value pairs. Its external @@ -240,7 +242,11 @@ public JSONObject(JSONTokener x) throws JSONException { * @throws JSONException */ public JSONObject(Map map) { - this.map = new HashMap(); + if (map instanceof SortedMap) { + this.map = new TreeMap(map); + } else { + this.map = new HashMap(); + } if (map != null) { Iterator i = map.entrySet().iterator(); while (i.hasNext()) { @@ -252,7 +258,7 @@ public JSONObject(Map map) { } } } - + /** * Construct a JSONObject from an Object using bean getters. It reflects on * all of the public methods of the object. For each of the methods with no