Skip to content

Commit

Permalink
Merge pull request #347 from ttulka/master
Browse files Browse the repository at this point in the history
a comment added to explain the use of HashMap
  • Loading branch information
stleary authored Jun 12, 2017
2 parents c9ae1f1 + 246350b commit 5b2e5e7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ public String toString() {
* Construct an empty JSONObject.
*/
public JSONObject() {
// HashMap is used on purpose to ensure that elements are unordered by
// the specification.
// JSON tends to be a portable transfer format to allows the container
// implementations to rearrange their items for a faster element
// retrieval based on associative access.
// Therefore, an implementation mustn't rely on the order of the item.
this.map = new HashMap<String, Object>();
}

Expand Down Expand Up @@ -216,15 +222,15 @@ public JSONObject(JSONTokener x) throws JSONException {
key = x.nextValue().toString();
}

// The key is followed by ':'.
// The key is followed by ':'.

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

// Pairs are separated by ','.
// Pairs are separated by ','.

switch (x.nextClean()) {
case ';':
Expand Down

0 comments on commit 5b2e5e7

Please sign in to comment.