Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The license includes this restriction: "The software shall be used for good,
not evil." If your conscience cannot live with that, then choose a different
package.

The package compiles on Java 1.2 thru Java 1.4.
The package compiles on Java 1.8.


JSONObject.java: The JSONObject can parse text from a String or a JSONTokener
Expand Down
11 changes: 7 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20131018</version>
<version>20141006</version>
<packaging>jar</packaging>

<name>JSON in Java</name>
Expand Down Expand Up @@ -88,8 +88,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.2</source>
<target>1.2</target>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -108,13 +108,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<version>2.9</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/json/CDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ of this software and associated documentation files (the "Software"), to deal
* The names for the elements in the JSONObjects can be taken from the names
* in the first row.
* @author JSON.org
* @version 2012-11-13
* @version 2014-05-03
*/
public class CDL {

Expand Down Expand Up @@ -142,7 +142,7 @@ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
* @return A string ending in NEWLINE.
*/
public static String rowToString(JSONArray ja) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ja.length(); i += 1) {
if (i > 0) {
sb.append(',');
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/json/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
* Convert a web browser cookie specification to a JSONObject and back.
* JSON and Cookies are both notations for name/value pairs.
* @author JSON.org
* @version 2010-12-24
* @version 2014-05-03
*/
public class Cookie {

Expand All @@ -45,10 +45,10 @@ public class Cookie {
* @return The escaped result.
*/
public static String escape(String string) {
char c;
String s = string.trim();
StringBuffer sb = new StringBuffer();
int length = s.length();
char c;
String s = string.trim();
int length = s.length();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i += 1) {
c = s.charAt(i);
if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
Expand Down Expand Up @@ -116,7 +116,7 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* @throws JSONException
*/
public static String toString(JSONObject jo) throws JSONException {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();

sb.append(escape(jo.getString("name")));
sb.append("=");
Expand Down Expand Up @@ -149,7 +149,7 @@ public static String toString(JSONObject jo) throws JSONException {
*/
public static String unescape(String string) {
int length = string.length();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; ++i) {
char c = string.charAt(i);
if (c == '+') {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/json/CookieList.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
/**
* Convert a web browser cookie list string to a JSONObject and back.
* @author JSON.org
* @version 2010-12-24
* @version 2014-05-03
*/
public class CookieList {

Expand Down Expand Up @@ -58,7 +58,6 @@ public static JSONObject toJSONObject(String string) throws JSONException {
return jo;
}


/**
* Convert a JSONObject into a cookie list. A cookie list is a sequence
* of name/value pairs. The names are separated from the values by '='.
Expand All @@ -69,12 +68,12 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* @throws JSONException
*/
public static String toString(JSONObject jo) throws JSONException {
boolean b = false;
Iterator keys = jo.keys();
String string;
StringBuffer sb = new StringBuffer();
boolean b = false;
Iterator<String> keys = jo.keys();
String string;
StringBuilder sb = new StringBuilder();
while (keys.hasNext()) {
string = keys.next().toString();
string = keys.next();
if (!jo.isNull(string)) {
if (b) {
sb.append(';');
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/json/HTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ of this software and associated documentation files (the "Software"), to deal
/**
* Convert an HTTP header to a JSONObject and back.
* @author JSON.org
* @version 2010-12-24
* @version 2014-05-03
*/
public class HTTP {

Expand Down Expand Up @@ -125,9 +125,9 @@ public static JSONObject toJSONObject(String string) throws JSONException {
* information.
*/
public static String toString(JSONObject jo) throws JSONException {
Iterator keys = jo.keys();
String string;
StringBuffer sb = new StringBuffer();
Iterator<String> keys = jo.keys();
String string;
StringBuilder sb = new StringBuilder();
if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
sb.append(jo.getString("HTTP-Version"));
sb.append(' ');
Expand All @@ -147,7 +147,7 @@ public static String toString(JSONObject jo) throws JSONException {
}
sb.append(CRLF);
while (keys.hasNext()) {
string = keys.next().toString();
string = keys.next();
if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) &&
!"Reason-Phrase".equals(string) && !"Method".equals(string) &&
!"Request-URI".equals(string) && !jo.isNull(string)) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/json/HTTPTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
* The HTTPTokener extends the JSONTokener to provide additional methods
* for the parsing of HTTP headers.
* @author JSON.org
* @version 2012-11-13
* @version 2014-05-03
*/
public class HTTPTokener extends JSONTokener {

Expand All @@ -49,7 +49,7 @@ public HTTPTokener(String string) {
public String nextToken() throws JSONException {
char c;
char q;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
do {
c = next();
} while (Character.isWhitespace(c));
Expand Down
61 changes: 47 additions & 14 deletions src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ of this software and associated documentation files (the "Software"), to deal
* </ul>
*
* @author JSON.org
* @version 2013-04-18
* @version 2014-05-03
*/
public class JSONArray {

/**
* The arrayList where the JSONArray's properties are kept.
*/
private final ArrayList myArrayList;
private final ArrayList<Object> myArrayList;

/**
* Construct an empty JSONArray.
*/
public JSONArray() {
this.myArrayList = new ArrayList();
this.myArrayList = new ArrayList<Object>();
}

/**
Expand Down Expand Up @@ -150,10 +150,10 @@ public JSONArray(String source) throws JSONException {
* @param collection
* A Collection.
*/
public JSONArray(Collection collection) {
this.myArrayList = new ArrayList();
public JSONArray(Collection<Object> collection) {
this.myArrayList = new ArrayList<Object>();
if (collection != null) {
Iterator iter = collection.iterator();
Iterator<Object> iter = collection.iterator();
while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next()));
}
Expand Down Expand Up @@ -357,7 +357,7 @@ public boolean isNull(int index) {
*/
public String join(String separator) throws JSONException {
int len = this.length();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();

for (int i = 0; i < len; i += 1) {
if (i > 0) {
Expand Down Expand Up @@ -593,7 +593,7 @@ public JSONArray put(boolean value) {
* A Collection value.
* @return this.
*/
public JSONArray put(Collection value) {
public JSONArray put(Collection<Object> value) {
this.put(new JSONArray(value));
return this;
}
Expand Down Expand Up @@ -646,7 +646,7 @@ public JSONArray put(long value) {
* A Map value.
* @return this.
*/
public JSONArray put(Map value) {
public JSONArray put(Map<String, Object> value) {
this.put(new JSONObject(value));
return this;
}
Expand Down Expand Up @@ -695,7 +695,7 @@ public JSONArray put(int index, boolean value) throws JSONException {
* @throws JSONException
* If the index is negative or if the value is not finite.
*/
public JSONArray put(int index, Collection value) throws JSONException {
public JSONArray put(int index, Collection<Object> value) throws JSONException {
this.put(index, new JSONArray(value));
return this;
}
Expand Down Expand Up @@ -767,7 +767,7 @@ public JSONArray put(int index, long value) throws JSONException {
* If the index is negative or if the the value is an invalid
* number.
*/
public JSONArray put(int index, Map value) throws JSONException {
public JSONArray put(int index, Map<String, Object> value) throws JSONException {
this.put(index, new JSONObject(value));
return this;
}
Expand Down Expand Up @@ -813,9 +813,42 @@ public JSONArray put(int index, Object value) throws JSONException {
* was no value.
*/
public Object remove(int index) {
Object o = this.opt(index);
this.myArrayList.remove(index);
return o;
return index >= 0 && index < this.length()
? this.myArrayList.remove(index)
: null;
}

/**
* Determine if two JSONArrays are similar.
* They must contain similar sequences.
*
* @param other The other JSONArray
* @return true if they are equal
*/
public boolean similar(Object other) {
if (!(other instanceof JSONArray)) {
return false;
}
int len = this.length();
if (len != ((JSONArray)other).length()) {
return false;
}
for (int i = 0; i < len; i += 1) {
Object valueThis = this.get(i);
Object valueOther = ((JSONArray)other).get(i);
if (valueThis instanceof JSONObject) {
if (!((JSONObject)valueThis).similar(valueOther)) {
return false;
}
} else if (valueThis instanceof JSONArray) {
if (!((JSONArray)valueThis).similar(valueOther)) {
return false;
}
} else if (!valueThis.equals(valueOther)) {
return false;
}
}
return true;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/json/JSONException.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* The JSONException is thrown by the JSON.org classes when things are amiss.
*
* @author JSON.org
* @version 2013-02-10
* @version 2014-05-03
*/
public class JSONException extends RuntimeException {
private static final long serialVersionUID = 0;
Expand All @@ -22,6 +22,7 @@ public JSONException(String message) {

/**
* Constructs a new JSONException with the specified cause.
* @param cause The cause.
*/
public JSONException(Throwable cause) {
super(cause.getMessage());
Expand All @@ -32,9 +33,10 @@ public JSONException(Throwable cause) {
* Returns the cause of this exception or null if the cause is nonexistent
* or unknown.
*
* @returns the cause of this exception or null if the cause is nonexistent
* @return the cause of this exception or null if the cause is nonexistent
* or unknown.
*/
@Override
public Throwable getCause() {
return this.cause;
}
Expand Down
Loading