Closed ozairjr closed 12 years ago
There are Java-5+ Generics compatible versions maintained by a few different forks, including my fork.
No thank you. They promised me "Write Once, Run Only" and I am holding them to that. I wrote it once, and I don't want to change it without getting some significant benefit. 5+ Generics don't do me any good at all.
Here's the code for Java version +1.5.
JSONObject.java
package org.json;
/* Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
import java.io.IOException; import java.io.Writer; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.Method; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle;
/**
get
andopt
methods forput
methods for adding orBoolean
,JSONArray
,JSONObject
,Number
,String
, or theJSONObject.NULL
get
andopt
methods, or to convert values into aput
andtoString
methods.get
method returns a value if one can be found, and throws anopt
method returns aget()
andopt()
methods return anget
andopt
methods that do type checking and typeput
methods add or replace values in an object. For example,{"JSON": "Hello, World"}
.toString
methods strictly conform to,
(comma) may appear just'
(single{ } [ ] / \ : , = ; #
and if they do not look like numberstrue
,false
, ornull
.=
or=>
as well as:
.;
(semicolon) as,
(comma).@version 2011-11-24 */ public class JSONObject {
/**
undefined. */ private static final class Null {
/**
@return NULL. */ protected final Object clone() { return this; }
/**
or null. */ public boolean equals(Object object) { return object == null || object == this; }
/**
/**
/**
NULL
object than to use Java'snull
value.JSONObject.NULL.equals(null)
returnstrue
.JSONObject.NULL.toString()
returns"null"
. */ public static final Object NULL = new Null();/**
/**
/**
if (x.nextClean() != '{') { throw x.syntaxError("A JSONObject text must begin with '{'"); } for (;;) { c = x.nextClean(); switch (c) { case 0: throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; default: x.back(); key = x.nextValue().toString(); }
// The key is followed by ':'. We will also tolerate '=' or '=>'.
// Pairs are separated by ','. We will also tolerate ';'.
// Iterate through the keys in the bundle.
// Go through the path, ensuring that there is a nested JSONObject for each // segment except the last. Add the value using the last segment's name into // the deepest nested JSONObject.
// Shave off trailing zeros and decimal point, if possible.
// Shave off trailing zeros and decimal point, if possible.
// If klass is a System class then set includeSuperClass to false.
}
JSONArray.java
package org.json;
/* Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
import java.io.IOException; import java.io.Writer; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.Map;
/**
get
andopt
put
methods forBoolean
,JSONArray
,JSONObject
,Number
,String
, or theJSONObject.NULL object
.toString
method converts to JSON text.get
method returns a value if one can be found, and throws anopt
method returns aget()
andopt()
methods return anget
andopt
methods that do type checking and typetoString
methods strictly conform to,
(comma) may appear justnull
value will be inserted when there,
(comma) elision.'
(single{ } [ ] / \ : , = ; #
and if they do not look like numberstrue
,false
, ornull
.;
(semicolon) as,
(comma).@version 2011-12-19 */ public class JSONArray {
/**
/**
/**
/**
[
(left bracket)]
(right bracket)./**
/**
/**
/**