diff --git a/JSONArray.java b/JSONArray.java index ec6eff5..066ea5f 100755 --- a/JSONArray.java +++ b/JSONArray.java @@ -73,12 +73,10 @@ import java.util.Map; * false, or null. *
  • Values can be separated by ; (semicolon) as * well as by , (comma).
  • - *
  • Numbers may have the - * 0x- (hex) prefix.
  • * * @author JSON.org - * @version 2011-08-25 + * @version 2011-11-24 */ public class JSONArray { @@ -86,7 +84,7 @@ public class JSONArray { /** * The arrayList where the JSONArray's properties are kept. */ - private ArrayList myArrayList; + private final ArrayList myArrayList; /** @@ -155,12 +153,12 @@ public class JSONArray { if (collection != null) { Iterator iter = collection.iterator(); while (iter.hasNext()) { - this.myArrayList.add(JSONObject.wrap(iter.next())); + this.myArrayList.add(JSONObject.wrap(iter.next())); } } } - + /** * Construct a JSONArray from an array * @throws JSONException If not an array. @@ -177,8 +175,8 @@ public class JSONArray { "JSONArray initial value should be a string or collection or array."); } } - - + + /** * Get the object value associated with an index. * @param index @@ -187,7 +185,7 @@ public class JSONArray { * @throws JSONException If there is no value for the index. */ public Object get(int index) throws JSONException { - Object object = opt(index); + Object object = this.opt(index); if (object == null) { throw new JSONException("JSONArray[" + index + "] not found."); } @@ -205,7 +203,7 @@ public class JSONArray { * value is not convertible to boolean. */ public boolean getBoolean(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) { @@ -228,11 +226,11 @@ public class JSONArray { * be converted to a number. */ public double getDouble(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); try { - return object instanceof Number ? - ((Number)object).doubleValue() : - Double.parseDouble((String)object); + return object instanceof Number + ? ((Number)object).doubleValue() + : Double.parseDouble((String)object); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); @@ -248,11 +246,11 @@ public class JSONArray { * @throws JSONException If the key is not found or if the value is not a number. */ public int getInt(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); try { - return object instanceof Number ? - ((Number)object).intValue() : - Integer.parseInt((String)object); + return object instanceof Number + ? ((Number)object).intValue() + : Integer.parseInt((String)object); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); @@ -268,7 +266,7 @@ public class JSONArray { * value is not a JSONArray */ public JSONArray getJSONArray(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); if (object instanceof JSONArray) { return (JSONArray)object; } @@ -285,7 +283,7 @@ public class JSONArray { * value is not a JSONObject */ public JSONObject getJSONObject(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); if (object instanceof JSONObject) { return (JSONObject)object; } @@ -303,11 +301,11 @@ public class JSONArray { * be converted to a number. */ public long getLong(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); try { - return object instanceof Number ? - ((Number)object).longValue() : - Long.parseLong((String)object); + return object instanceof Number + ? ((Number)object).longValue() + : Long.parseLong((String)object); } catch (Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); @@ -322,7 +320,7 @@ public class JSONArray { * @throws JSONException If there is no string value for the index. */ public String getString(int index) throws JSONException { - Object object = get(index); + Object object = this.get(index); if (object instanceof String) { return (String)object; } @@ -336,7 +334,7 @@ public class JSONArray { * @return true if the value at the index is null, or if there is no value. */ public boolean isNull(int index) { - return JSONObject.NULL.equals(opt(index)); + return JSONObject.NULL.equals(this.opt(index)); } @@ -349,7 +347,7 @@ public class JSONArray { * @throws JSONException If the array contains an invalid number. */ public String join(String separator) throws JSONException { - int len = length(); + int len = this.length(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i += 1) { @@ -379,8 +377,9 @@ public class JSONArray { * object at that index. */ public Object opt(int index) { - return (index < 0 || index >= length()) ? - null : this.myArrayList.get(index); + return (index < 0 || index >= this.length()) + ? null + : this.myArrayList.get(index); } @@ -393,7 +392,7 @@ public class JSONArray { * @return The truth. */ public boolean optBoolean(int index) { - return optBoolean(index, false); + return this.optBoolean(index, false); } @@ -408,7 +407,7 @@ public class JSONArray { */ public boolean optBoolean(int index, boolean defaultValue) { try { - return getBoolean(index); + return this.getBoolean(index); } catch (Exception e) { return defaultValue; } @@ -424,7 +423,7 @@ public class JSONArray { * @return The value. */ public double optDouble(int index) { - return optDouble(index, Double.NaN); + return this.optDouble(index, Double.NaN); } @@ -439,7 +438,7 @@ public class JSONArray { */ public double optDouble(int index, double defaultValue) { try { - return getDouble(index); + return this.getDouble(index); } catch (Exception e) { return defaultValue; } @@ -455,7 +454,7 @@ public class JSONArray { * @return The value. */ public int optInt(int index) { - return optInt(index, 0); + return this.optInt(index, 0); } @@ -469,7 +468,7 @@ public class JSONArray { */ public int optInt(int index, int defaultValue) { try { - return getInt(index); + return this.getInt(index); } catch (Exception e) { return defaultValue; } @@ -483,7 +482,7 @@ public class JSONArray { * or if the value is not a JSONArray. */ public JSONArray optJSONArray(int index) { - Object o = opt(index); + Object o = this.opt(index); return o instanceof JSONArray ? (JSONArray)o : null; } @@ -497,7 +496,7 @@ public class JSONArray { * @return A JSONObject value. */ public JSONObject optJSONObject(int index) { - Object o = opt(index); + Object o = this.opt(index); return o instanceof JSONObject ? (JSONObject)o : null; } @@ -511,7 +510,7 @@ public class JSONArray { * @return The value. */ public long optLong(int index) { - return optLong(index, 0); + return this.optLong(index, 0); } @@ -525,7 +524,7 @@ public class JSONArray { */ public long optLong(int index, long defaultValue) { try { - return getLong(index); + return this.getLong(index); } catch (Exception e) { return defaultValue; } @@ -541,7 +540,7 @@ public class JSONArray { * @return A String value. */ public String optString(int index) { - return optString(index, ""); + return this.optString(index, ""); } @@ -554,8 +553,10 @@ public class JSONArray { * @return A String value. */ public String optString(int index, String defaultValue) { - Object object = opt(index); - return JSONObject.NULL.equals(object) ? object.toString() : defaultValue; + Object object = this.opt(index); + return JSONObject.NULL.equals(object) + ? object.toString() + : defaultValue; } @@ -566,7 +567,7 @@ public class JSONArray { * @return this. */ public JSONArray put(boolean value) { - put(value ? Boolean.TRUE : Boolean.FALSE); + this.put(value ? Boolean.TRUE : Boolean.FALSE); return this; } @@ -578,7 +579,7 @@ public class JSONArray { * @return this. */ public JSONArray put(Collection value) { - put(new JSONArray(value)); + this.put(new JSONArray(value)); return this; } @@ -593,7 +594,7 @@ public class JSONArray { public JSONArray put(double value) throws JSONException { Double d = new Double(value); JSONObject.testValidity(d); - put(d); + this.put(d); return this; } @@ -605,7 +606,7 @@ public class JSONArray { * @return this. */ public JSONArray put(int value) { - put(new Integer(value)); + this.put(new Integer(value)); return this; } @@ -617,7 +618,7 @@ public class JSONArray { * @return this. */ public JSONArray put(long value) { - put(new Long(value)); + this.put(new Long(value)); return this; } @@ -629,7 +630,7 @@ public class JSONArray { * @return this. */ public JSONArray put(Map value) { - put(new JSONObject(value)); + this.put(new JSONObject(value)); return this; } @@ -657,7 +658,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public JSONArray put(int index, boolean value) throws JSONException { - put(index, value ? Boolean.TRUE : Boolean.FALSE); + this.put(index, value ? Boolean.TRUE : Boolean.FALSE); return this; } @@ -672,7 +673,7 @@ public class JSONArray { * not finite. */ public JSONArray put(int index, Collection value) throws JSONException { - put(index, new JSONArray(value)); + this.put(index, new JSONArray(value)); return this; } @@ -688,7 +689,7 @@ public class JSONArray { * not finite. */ public JSONArray put(int index, double value) throws JSONException { - put(index, new Double(value)); + this.put(index, new Double(value)); return this; } @@ -703,7 +704,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public JSONArray put(int index, int value) throws JSONException { - put(index, new Integer(value)); + this.put(index, new Integer(value)); return this; } @@ -718,7 +719,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public JSONArray put(int index, long value) throws JSONException { - put(index, new Long(value)); + this.put(index, new Long(value)); return this; } @@ -733,7 +734,7 @@ public class JSONArray { * an invalid number. */ public JSONArray put(int index, Map value) throws JSONException { - put(index, new JSONObject(value)); + this.put(index, new JSONObject(value)); return this; } @@ -755,18 +756,18 @@ public class JSONArray { if (index < 0) { throw new JSONException("JSONArray[" + index + "] not found."); } - if (index < length()) { + if (index < this.length()) { this.myArrayList.set(index, value); } else { - while (index != length()) { - put(JSONObject.NULL); + while (index != this.length()) { + this.put(JSONObject.NULL); } - put(value); + this.put(value); } return this; } - - + + /** * Remove an index and close the hole. * @param index The index of the element to be removed. @@ -774,7 +775,7 @@ public class JSONArray { * or null if there was no value. */ public Object remove(int index) { - Object o = opt(index); + Object o = this.opt(index); this.myArrayList.remove(index); return o; } @@ -790,7 +791,7 @@ public class JSONArray { * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { - if (names == null || names.length() == 0 || length() == 0) { + if (names == null || names.length() == 0 || this.length() == 0) { return null; } JSONObject jo = new JSONObject(); @@ -814,7 +815,7 @@ public class JSONArray { */ public String toString() { try { - return '[' + join(",") + ']'; + return '[' + this.join(",") + ']'; } catch (Exception e) { return null; } @@ -833,7 +834,7 @@ public class JSONArray { * @throws JSONException */ public String toString(int indentFactor) throws JSONException { - return toString(indentFactor, 0); + return this.toString(indentFactor, 0); } @@ -848,7 +849,7 @@ public class JSONArray { * @throws JSONException */ String toString(int indentFactor, int indent) throws JSONException { - int len = length(); + int len = this.length(); if (len == 0) { return "[]"; } @@ -892,7 +893,7 @@ public class JSONArray { public Writer write(Writer writer) throws JSONException { try { boolean b = false; - int len = length(); + int len = this.length(); writer.write('['); diff --git a/JSONObject.java b/JSONObject.java index 5f3ceec..c4ad550 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -83,10 +83,9 @@ import java.util.ResourceBundle; * by :. *
  • Values can be followed by ; (semicolon) as * well as by , (comma).
  • - *
  • Numbers may have the 0x- (hex) prefix.
  • * * @author JSON.org - * @version 2011-10-16 + * @version 2011-11-24 */ public class JSONObject { @@ -129,7 +128,7 @@ public class JSONObject { /** * The map where the JSONObject's properties are kept. */ - private Map map; + private final Map map; /** @@ -162,7 +161,7 @@ public class JSONObject { this(); for (int i = 0; i < names.length; i += 1) { try { - putOnce(names[i], jo.opt(names[i])); + this.putOnce(names[i], jo.opt(names[i])); } catch (Exception ignore) { } } @@ -205,7 +204,7 @@ public class JSONObject { } else if (c != ':') { throw x.syntaxError("Expected a ':' after a key"); } - putOnce(key, x.nextValue()); + this.putOnce(key, x.nextValue()); // Pairs are separated by ','. We will also tolerate ';'. @@ -269,7 +268,7 @@ public class JSONObject { */ public JSONObject(Object bean) { this(); - populateMap(bean); + this.populateMap(bean); } @@ -290,7 +289,7 @@ public class JSONObject { for (int i = 0; i < names.length; i += 1) { String name = names[i]; try { - putOpt(name, c.getField(name).get(object)); + this.putOpt(name, c.getField(name).get(object)); } catch (Exception ignore) { } } @@ -372,14 +371,15 @@ public class JSONObject { Object value ) throws JSONException { testValidity(value); - Object object = opt(key); + Object object = this.opt(key); if (object == null) { - put(key, value instanceof JSONArray ? - new JSONArray().put(value) : value); + this.put(key, value instanceof JSONArray + ? new JSONArray().put(value) + : value); } else if (object instanceof JSONArray) { ((JSONArray)object).put(value); } else { - put(key, new JSONArray().put(object).put(value)); + this.put(key, new JSONArray().put(object).put(value)); } return this; } @@ -398,11 +398,11 @@ public class JSONObject { */ public JSONObject append(String key, Object value) throws JSONException { testValidity(value); - Object object = opt(key); + Object object = this.opt(key); if (object == null) { - put(key, new JSONArray().put(value)); + this.put(key, new JSONArray().put(value)); } else if (object instanceof JSONArray) { - put(key, ((JSONArray)object).put(value)); + this.put(key, ((JSONArray)object).put(value)); } else { throw new JSONException("JSONObject[" + key + "] is not a JSONArray."); @@ -449,7 +449,7 @@ public class JSONObject { if (key == null) { throw new JSONException("Null key."); } - Object object = opt(key); + Object object = this.opt(key); if (object == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); @@ -467,7 +467,7 @@ public class JSONObject { * if the value is not a Boolean or the String "true" or "false". */ public boolean getBoolean(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) { @@ -490,11 +490,11 @@ public class JSONObject { * if the value is not a Number object and cannot be converted to a number. */ public double getDouble(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); try { - return object instanceof Number ? - ((Number)object).doubleValue() : - Double.parseDouble((String)object); + return object instanceof Number + ? ((Number)object).doubleValue() + : Double.parseDouble((String)object); } catch (Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); @@ -511,11 +511,11 @@ public class JSONObject { * be converted to an integer. */ public int getInt(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); try { - return object instanceof Number ? - ((Number)object).intValue() : - Integer.parseInt((String)object); + return object instanceof Number + ? ((Number)object).intValue() + : Integer.parseInt((String)object); } catch (Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not an int."); @@ -532,7 +532,7 @@ public class JSONObject { * if the value is not a JSONArray. */ public JSONArray getJSONArray(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); if (object instanceof JSONArray) { return (JSONArray)object; } @@ -550,7 +550,7 @@ public class JSONObject { * if the value is not a JSONObject. */ public JSONObject getJSONObject(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); if (object instanceof JSONObject) { return (JSONObject)object; } @@ -568,11 +568,11 @@ public class JSONObject { * be converted to a long. */ public long getLong(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); try { - return object instanceof Number ? - ((Number)object).longValue() : - Long.parseLong((String)object); + return object instanceof Number + ? ((Number)object).longValue() + : Long.parseLong((String)object); } catch (Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a long."); @@ -632,7 +632,7 @@ public class JSONObject { * @throws JSONException if there is no string value for the key. */ public String getString(String key) throws JSONException { - Object object = get(key); + Object object = this.get(key); if (object instanceof String) { return (String)object; } @@ -661,17 +661,17 @@ public class JSONObject { * that is not an Integer, Long, Double, or Float. */ public JSONObject increment(String key) throws JSONException { - Object value = opt(key); + Object value = this.opt(key); if (value == null) { - put(key, 1); + this.put(key, 1); } else if (value instanceof Integer) { - put(key, ((Integer)value).intValue() + 1); + this.put(key, ((Integer)value).intValue() + 1); } else if (value instanceof Long) { - put(key, ((Long)value).longValue() + 1); + this.put(key, ((Long)value).longValue() + 1); } else if (value instanceof Double) { - put(key, ((Double)value).doubleValue() + 1); + this.put(key, ((Double)value).doubleValue() + 1); } else if (value instanceof Float) { - put(key, ((Float)value).floatValue() + 1); + this.put(key, ((Float)value).floatValue() + 1); } else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } @@ -687,7 +687,7 @@ public class JSONObject { * the value is the JSONObject.NULL object. */ public boolean isNull(String key) { - return JSONObject.NULL.equals(opt(key)); + return JSONObject.NULL.equals(this.opt(key)); } @@ -774,7 +774,7 @@ public class JSONObject { * @return The truth. */ public boolean optBoolean(String key) { - return optBoolean(key, false); + return this.optBoolean(key, false); } @@ -789,7 +789,7 @@ public class JSONObject { */ public boolean optBoolean(String key, boolean defaultValue) { try { - return getBoolean(key); + return this.getBoolean(key); } catch (Exception e) { return defaultValue; } @@ -806,7 +806,7 @@ public class JSONObject { * @return An object which is the value. */ public double optDouble(String key) { - return optDouble(key, Double.NaN); + return this.optDouble(key, Double.NaN); } @@ -822,7 +822,7 @@ public class JSONObject { */ public double optDouble(String key, double defaultValue) { try { - return getDouble(key); + return this.getDouble(key); } catch (Exception e) { return defaultValue; } @@ -839,7 +839,7 @@ public class JSONObject { * @return An object which is the value. */ public int optInt(String key) { - return optInt(key, 0); + return this.optInt(key, 0); } @@ -855,7 +855,7 @@ public class JSONObject { */ public int optInt(String key, int defaultValue) { try { - return getInt(key); + return this.getInt(key); } catch (Exception e) { return defaultValue; } @@ -871,7 +871,7 @@ public class JSONObject { * @return A JSONArray which is the value. */ public JSONArray optJSONArray(String key) { - Object o = opt(key); + Object o = this.opt(key); return o instanceof JSONArray ? (JSONArray)o : null; } @@ -885,7 +885,7 @@ public class JSONObject { * @return A JSONObject which is the value. */ public JSONObject optJSONObject(String key) { - Object object = opt(key); + Object object = this.opt(key); return object instanceof JSONObject ? (JSONObject)object : null; } @@ -900,7 +900,7 @@ public class JSONObject { * @return An object which is the value. */ public long optLong(String key) { - return optLong(key, 0); + return this.optLong(key, 0); } @@ -916,7 +916,7 @@ public class JSONObject { */ public long optLong(String key, long defaultValue) { try { - return getLong(key); + return this.getLong(key); } catch (Exception e) { return defaultValue; } @@ -932,7 +932,7 @@ public class JSONObject { * @return A string which is the value. */ public String optString(String key) { - return optString(key, ""); + return this.optString(key, ""); } @@ -945,7 +945,7 @@ public class JSONObject { * @return A string which is the value. */ public String optString(String key, String defaultValue) { - Object object = opt(key); + Object object = this.opt(key); return NULL.equals(object) ? defaultValue : object.toString(); } @@ -957,8 +957,9 @@ public class JSONObject { boolean includeSuperClass = klass.getClassLoader() != null; - Method[] methods = (includeSuperClass) ? - klass.getMethods() : klass.getDeclaredMethods(); + Method[] methods = includeSuperClass + ? klass.getMethods() + : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try { Method method = methods[i]; @@ -987,7 +988,7 @@ public class JSONObject { Object result = method.invoke(bean, (Object[])null); if (result != null) { - map.put(key, wrap(result)); + this.map.put(key, wrap(result)); } } } @@ -1006,7 +1007,7 @@ public class JSONObject { * @throws JSONException If the key is null. */ public JSONObject put(String key, boolean value) throws JSONException { - put(key, value ? Boolean.TRUE : Boolean.FALSE); + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); return this; } @@ -1020,7 +1021,7 @@ public class JSONObject { * @throws JSONException */ public JSONObject put(String key, Collection value) throws JSONException { - put(key, new JSONArray(value)); + this.put(key, new JSONArray(value)); return this; } @@ -1034,7 +1035,7 @@ public class JSONObject { * @throws JSONException If the key is null or if the number is invalid. */ public JSONObject put(String key, double value) throws JSONException { - put(key, new Double(value)); + this.put(key, new Double(value)); return this; } @@ -1048,7 +1049,7 @@ public class JSONObject { * @throws JSONException If the key is null. */ public JSONObject put(String key, int value) throws JSONException { - put(key, new Integer(value)); + this.put(key, new Integer(value)); return this; } @@ -1062,7 +1063,7 @@ public class JSONObject { * @throws JSONException If the key is null. */ public JSONObject put(String key, long value) throws JSONException { - put(key, new Long(value)); + this.put(key, new Long(value)); return this; } @@ -1076,7 +1077,7 @@ public class JSONObject { * @throws JSONException */ public JSONObject put(String key, Map value) throws JSONException { - put(key, new JSONObject(value)); + this.put(key, new JSONObject(value)); return this; } @@ -1100,7 +1101,7 @@ public class JSONObject { testValidity(value); this.map.put(key, value); } else { - remove(key); + this.remove(key); } return this; } @@ -1117,10 +1118,10 @@ public class JSONObject { */ public JSONObject putOnce(String key, Object value) throws JSONException { if (key != null && value != null) { - if (opt(key) != null) { + if (this.opt(key) != null) { throw new JSONException("Duplicate key \"" + key + "\""); } - put(key, value); + this.put(key, value); } return this; } @@ -1138,7 +1139,7 @@ public class JSONObject { */ public JSONObject putOpt(String key, Object value) throws JSONException { if (key != null && value != null) { - put(key, value); + this.put(key, value); } return this; } @@ -1242,22 +1243,14 @@ public class JSONObject { /* * If it might be a number, try converting it. - * We support the non-standard 0x- convention. * If a number cannot be produced, then the value will just - * be a string. Note that the 0x-, plus, and implied string + * be a string. Note that the plus and implied string * conventions are non-standard. A JSON parser may accept * non-JSON forms as long as it accepts all correct JSON forms. */ char b = string.charAt(0); if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { - if (b == '0' && string.length() > 2 && - (string.charAt(1) == 'x' || string.charAt(1) == 'X')) { - try { - return new Integer(Integer.parseInt(string.substring(2), 16)); - } catch (Exception ignore) { - } - } try { if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { @@ -1368,7 +1361,7 @@ public class JSONObject { * @throws JSONException If the object contains an invalid number. */ public String toString(int indentFactor) throws JSONException { - return toString(indentFactor, 0); + return this.toString(indentFactor, 0); } @@ -1579,8 +1572,9 @@ public class JSONObject { return new JSONObject((Map)object); } Package objectPackage = object.getClass().getPackage(); - String objectPackageName = objectPackage != null ? - objectPackage.getName() : ""; + String objectPackageName = objectPackage != null + ? objectPackage.getName() + : ""; if ( objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || diff --git a/Test.java b/Test.java index 523734c..7cf8c32 100755 --- a/Test.java +++ b/Test.java @@ -496,14 +496,14 @@ public class Test extends TestCase { XML.toString(jsonarray)); jsonobject = new JSONObject("{ fun => with non-standard forms ; forgiving => This package can be used to parse formats that are similar to but not stricting conforming to JSON; why=To make it easier to migrate existing data to JSON,one = [[1.00]]; uno=[[{1=>1}]];'+':+6e66 ;pluses=+++;empty = '' , 'double':0.666,true: TRUE, false: FALSE, null=NULL;[true] = [[!,@;*]]; string=> o. k. ; \r oct=0666; hex=0x666; dec=666; o=0999; noh=0x0x}"); - assertEquals("{\n \"noh\": \"0x0x\",\n \"one\": [[1]],\n \"o\": 999,\n \"+\": 6.0E66,\n \"true\": true,\n \"forgiving\": \"This package can be used to parse formats that are similar to but not stricting conforming to JSON\",\n \"fun\": \"with non-standard forms\",\n \"double\": 0.666,\n \"uno\": [[{\"1\": 1}]],\n \"dec\": 666,\n \"oct\": 666,\n \"hex\": 1638,\n \"string\": \"o. k.\",\n \"empty\": \"\",\n \"false\": false,\n \"[true]\": [[\n \"!\",\n \"@\",\n \"*\"\n ]],\n \"pluses\": \"+++\",\n \"why\": \"To make it easier to migrate existing data to JSON\",\n \"null\": null\n}", jsonobject.toString(1)); + assertEquals("{\n \"noh\": \"0x0x\",\n \"one\": [[1]],\n \"o\": 999,\n \"+\": 6.0E66,\n \"true\": true,\n \"forgiving\": \"This package can be used to parse formats that are similar to but not stricting conforming to JSON\",\n \"fun\": \"with non-standard forms\",\n \"double\": 0.666,\n \"uno\": [[{\"1\": 1}]],\n \"dec\": 666,\n \"oct\": 666,\n \"hex\": \"0x666\",\n \"string\": \"o. k.\",\n \"empty\": \"\",\n \"false\": false,\n \"[true]\": [[\n \"!\",\n \"@\",\n \"*\"\n ]],\n \"pluses\": \"+++\",\n \"why\": \"To make it easier to migrate existing data to JSON\",\n \"null\": null\n}", jsonobject.toString(1)); assertTrue(jsonobject.getBoolean("true")); assertFalse(jsonobject.getBoolean("false")); jsonobject = new JSONObject(jsonobject, new String[]{"dec", "oct", "hex", "missing"}); - assertEquals("{\n \"oct\": 666,\n \"dec\": 666,\n \"hex\": 1638\n}", jsonobject.toString(1)); + assertEquals("{\n \"oct\": 666,\n \"dec\": 666,\n \"hex\": \"0x666\"\n}", jsonobject.toString(1)); - assertEquals("[[\"\",\"next is an implied null\",null,\"ok\"],{\"oct\":666,\"dec\":666,\"hex\":1638}]", + assertEquals("[[\"\",\"next is an implied null\",null,\"ok\"],{\"oct\":666,\"dec\":666,\"hex\":\"0x666\"}]", new JSONStringer().array().value(jsonarray).value(jsonobject).endArray().toString()); jsonobject = new JSONObject("{string: \"98.6\", long: 2147483648, int: 2147483647, longer: 9223372036854775807, double: 9223372036854775808}");