Skip to content

Commit 5b2e5e7

Browse files
authored
Merge pull request stleary#347 from ttulka/master
a comment added to explain the use of HashMap
2 parents c9ae1f1 + 246350b commit 5b2e5e7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

JSONObject.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ public String toString() {
164164
* Construct an empty JSONObject.
165165
*/
166166
public JSONObject() {
167+
// HashMap is used on purpose to ensure that elements are unordered by
168+
// the specification.
169+
// JSON tends to be a portable transfer format to allows the container
170+
// implementations to rearrange their items for a faster element
171+
// retrieval based on associative access.
172+
// Therefore, an implementation mustn't rely on the order of the item.
167173
this.map = new HashMap<String, Object>();
168174
}
169175

@@ -216,15 +222,15 @@ public JSONObject(JSONTokener x) throws JSONException {
216222
key = x.nextValue().toString();
217223
}
218224

219-
// The key is followed by ':'.
225+
// The key is followed by ':'.
220226

221227
c = x.nextClean();
222228
if (c != ':') {
223229
throw x.syntaxError("Expected a ':' after a key");
224230
}
225231
this.putOnce(key, x.nextValue());
226232

227-
// Pairs are separated by ','.
233+
// Pairs are separated by ','.
228234

229235
switch (x.nextClean()) {
230236
case ';':

0 commit comments

Comments
 (0)