Changeset 23191 in osm for applications/editors/josm/plugins/livegps/src/org/json/JSONObject.java
- Timestamp:
- 2010-09-15T18:56:19+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified applications/editors/josm/plugins/livegps/src/org/json/JSONObject.java ¶
r21622 r23191 155 155 * @param jo A JSONObject. 156 156 * @param names An array of strings. 157 * @throws JSONException 157 * @throws JSONException 158 158 * @exception JSONException If a value is a non-finite number or if a name is duplicated. 159 159 */ … … 161 161 this(); 162 162 for (int i = 0; i < names.length; i += 1) { 163 164 165 166 163 try { 164 putOnce(names[i], jo.opt(names[i])); 165 } catch (Exception ignore) { 166 } 167 167 } 168 168 } … … 235 235 * @param map A map object that can be used to initialize the contents of 236 236 * the JSONObject. 237 * @throws JSONException 237 * @throws JSONException 238 238 */ 239 239 public JSONObject(Map map) { … … 455 455 456 456 /** 457 * Get the int value associated with a key. 457 * Get the int value associated with a key. 458 458 * 459 459 * @param key A key string. … … 512 512 513 513 /** 514 * Get the long value associated with a key. 514 * Get the long value associated with a key. 515 515 * 516 516 * @param key A key string. … … 596 596 return this.map.containsKey(key); 597 597 } 598 599 598 599 600 600 /** 601 601 * Increment a property of a JSONObject. If there is no such property, … … 608 608 */ 609 609 public JSONObject increment(String key) throws JSONException { 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 610 Object value = opt(key); 611 if (value == null) { 612 put(key, 1); 613 } else { 614 if (value instanceof Integer) { 615 put(key, ((Integer)value).intValue() + 1); 616 } else if (value instanceof Long) { 617 put(key, ((Long)value).longValue() + 1); 618 } else if (value instanceof Double) { 619 put(key, ((Double)value).doubleValue() + 1); 620 } else if (value instanceof Float) { 621 put(key, ((Float)value).floatValue() + 1); 622 } else { 623 throw new JSONException("Unable to increment [" + key + "]."); 624 } 625 } 626 return this; 627 627 } 628 628 … … 903 903 Class klass = bean.getClass(); 904 904 905 // If klass is a System class then set includeSuperClass to false. 905 // If klass is a System class then set includeSuperClass to false. 906 906 907 907 boolean includeSuperClass = klass.getClassLoader() != null; … … 916 916 String key = ""; 917 917 if (name.startsWith("get")) { 918 919 920 921 922 923 918 if (name.equals("getClass") || 919 name.equals("getDeclaringClass")) { 920 key = ""; 921 } else { 922 key = name.substring(3); 923 } 924 924 } else if (name.startsWith("is")) { 925 925 key = name.substring(2); … … 1199 1199 1200 1200 /* 1201 * If it might be a number, try converting it. 1202 * We support the non-standard 0x- convention. 1201 * If it might be a number, try converting it. 1202 * We support the non-standard 0x- convention. 1203 1203 * If a number cannot be produced, then the value will just 1204 1204 * be a string. Note that the 0x-, plus, and implied string … … 1217 1217 } 1218 1218 try { 1219 if (s.indexOf('.') > -1 || 1220 1219 if (s.indexOf('.') > -1 || 1220 s.indexOf('e') > -1 || s.indexOf('E') > -1) { 1221 1221 return Double.valueOf(s); 1222 1222 } else { … … 1495 1495 1496 1496 /** 1497 * Wrap an object, if necessary. If the object is null, return the NULL 1498 * object. If it is an array or collection, wrap it in a JSONArray. If 1499 * it is a map, wrap it in a JSONObject. If it is a standard property 1500 * (Double, String, et al) then it is already wrapped. Otherwise, if it 1501 * comes from one of the java packages, turn it into a string. And if 1497 * Wrap an object, if necessary. If the object is null, return the NULL 1498 * object. If it is an array or collection, wrap it in a JSONArray. If 1499 * it is a map, wrap it in a JSONObject. If it is a standard property 1500 * (Double, String, et al) then it is already wrapped. Otherwise, if it 1501 * comes from one of the java packages, turn it into a string. And if 1502 1502 * it doesn't, try to wrap it in a JSONObject. If the wrapping fails, 1503 1503 * then null is returned. … … 1511 1511 return NULL; 1512 1512 } 1513 if (object instanceof JSONObject || object instanceof JSONArray || 1514 1515 1513 if (object instanceof JSONObject || object instanceof JSONArray || 1514 NULL.equals(object) || object instanceof JSONString || 1515 object instanceof Byte || object instanceof Character || 1516 1516 object instanceof Short || object instanceof Integer || 1517 object instanceof Long || object instanceof Boolean || 1517 object instanceof Long || object instanceof Boolean || 1518 1518 object instanceof Float || object instanceof Double || 1519 1519 object instanceof String) { 1520 1520 return object; 1521 1521 } 1522 1522 1523 1523 if (object instanceof Collection) { 1524 1524 return new JSONArray((Collection)object); … … 1533 1533 String objectPackageName = ( objectPackage != null ? objectPackage.getName() : "" ); 1534 1534 if (objectPackageName.startsWith("java.") || 1535 1536 1535 objectPackageName.startsWith("javax.") || 1536 object.getClass().getClassLoader() == null) { 1537 1537 return object.toString(); 1538 1538 } … … 1543 1543 } 1544 1544 1545 1545 1546 1546 /** 1547 1547 * Write the contents of the JSONObject as JSON text to a writer.
Note:
See TracChangeset
for help on using the changeset viewer.