Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -157,6 +158,16 @@ public JSONObject() {
this.map = new HashMap<String, Object>();
}

/**
* Construct an empty JSONObject.
*
* @param ordered
* if ordered == true, then the JSONObject keeps the original order of properties
*/
public JSONObject(boolean ordered) {
this.map = ordered ? new LinkedHashMap<String, Object>() : new HashMap<String, Object>();
}

/**
* Construct a JSONObject from a subset of another JSONObject. An array of
* strings is used to identify the keys that should be copied. Missing keys
Expand Down Expand Up @@ -240,7 +251,7 @@ public JSONObject(JSONTokener x) throws JSONException {
* the JSONObject.
*/
public JSONObject(Map<?, ?> map) {
this.map = new HashMap<String, Object>();
this.map = map instanceof LinkedHashMap ? new LinkedHashMap<String, Object>() : new HashMap<String, Object>();
if (map != null) {
for (final Entry<?, ?> e : map.entrySet()) {
final Object value = e.getValue();
Expand Down