@@ -36,7 +36,6 @@ of this software and associated documentation files (the "Software"), to deal
36
36
import java .util .Locale ;
37
37
import java .util .Map ;
38
38
import java .util .ResourceBundle ;
39
- import java .util .TreeSet ;
40
39
41
40
/**
42
41
* A JSONObject is an unordered collection of name/value pairs. Its
@@ -87,7 +86,7 @@ of this software and associated documentation files (the "Software"), to deal
87
86
* <li>Numbers may have the <code>0x-</code> <small>(hex)</small> prefix.</li>
88
87
* </ul>
89
88
* @author JSON.org
90
- * @version 2010-12-28
89
+ * @version 2011-01-31
91
90
*/
92
91
public class JSONObject {
93
92
@@ -320,12 +319,12 @@ public JSONObject(String source) throws JSONException {
320
319
*/
321
320
public JSONObject (String baseName , Locale locale ) throws JSONException {
322
321
this ();
323
- ResourceBundle r = ResourceBundle .getBundle (baseName , locale ,
322
+ ResourceBundle bundle = ResourceBundle .getBundle (baseName , locale ,
324
323
Thread .currentThread ().getContextClassLoader ());
325
324
326
325
// Iterate through the keys in the bundle.
327
326
328
- Enumeration keys = r .getKeys ();
327
+ Enumeration keys = bundle .getKeys ();
329
328
while (keys .hasMoreElements ()) {
330
329
Object key = keys .nextElement ();
331
330
if (key instanceof String ) {
@@ -346,7 +345,7 @@ public JSONObject(String baseName, Locale locale) throws JSONException {
346
345
}
347
346
target = nextTarget ;
348
347
}
349
- target .put (path [last ], r .getString ((String )key ));
348
+ target .put (path [last ], bundle .getString ((String )key ));
350
349
}
351
350
}
352
351
}
@@ -358,6 +357,10 @@ public JSONObject(String baseName, Locale locale) throws JSONException {
358
357
* JSONArray is stored under the key to hold all of the accumulated values.
359
358
* If there is already a JSONArray, then the new value is appended to it.
360
359
* In contrast, the put method replaces the previous value.
360
+ *
361
+ * If only one value is accumulated that is not a JSONArray, then the
362
+ * result will be the same as using put. But if multiple values are
363
+ * accumulated, then the result will be like append.
361
364
* @param key A key string.
362
365
* @param value An object to be accumulated under the key.
363
366
* @return this.
@@ -710,7 +713,7 @@ public int length() {
710
713
*/
711
714
public JSONArray names () {
712
715
JSONArray ja = new JSONArray ();
713
- Iterator keys = keys ();
716
+ Iterator keys = this . keys ();
714
717
while (keys .hasNext ()) {
715
718
ja .put (keys .next ());
716
719
}
@@ -1210,16 +1213,6 @@ public Object remove(String key) {
1210
1213
return this .map .remove (key );
1211
1214
}
1212
1215
1213
- /**
1214
- * Get an enumeration of the keys of the JSONObject.
1215
- * The keys will be sorted alphabetically.
1216
- *
1217
- * @return An iterator of the keys.
1218
- */
1219
- public Iterator sortedKeys () {
1220
- return new TreeSet (this .map .keySet ()).iterator ();
1221
- }
1222
-
1223
1216
/**
1224
1217
* Try to convert a string into a number, boolean, or null. If the string
1225
1218
* can't be converted, return the string.
@@ -1332,7 +1325,7 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
1332
1325
*/
1333
1326
public String toString () {
1334
1327
try {
1335
- Iterator keys = keys ();
1328
+ Iterator keys = this . keys ();
1336
1329
StringBuffer sb = new StringBuffer ("{" );
1337
1330
1338
1331
while (keys .hasNext ()) {
@@ -1388,7 +1381,7 @@ String toString(int indentFactor, int indent) throws JSONException {
1388
1381
if (length == 0 ) {
1389
1382
return "{}" ;
1390
1383
}
1391
- Iterator keys = sortedKeys ();
1384
+ Iterator keys = this . keys ();
1392
1385
int newindent = indent + indentFactor ;
1393
1386
Object object ;
1394
1387
StringBuffer sb = new StringBuffer ("{" );
@@ -1598,7 +1591,7 @@ public static Object wrap(Object object) {
1598
1591
public Writer write (Writer writer ) throws JSONException {
1599
1592
try {
1600
1593
boolean commanate = false ;
1601
- Iterator keys = keys ();
1594
+ Iterator keys = this . keys ();
1602
1595
writer .write ('{' );
1603
1596
1604
1597
while (keys .hasNext ()) {
0 commit comments