package org.json;
/*
Public Domain.
*/
import java.io.Closeable;
import java.io.IOException;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.GenericArrayType;
/**
* A JSONObject is an unordered collection of name/value pairs. Its external
* form is a string wrapped in curly braces with colons between the names and
* values, and commas between the values and names. The internal form is an
* object having get and opt methods for accessing
* the values by name, and put methods for adding or replacing
* values by name. The values can be any of these types: Boolean,
* JSONArray, JSONObject, Number,
* String, or the JSONObject.NULL object. A
* JSONObject constructor can be used to convert an external form JSON text
* into an internal form whose values can be retrieved with the
* get and opt methods, or to convert values into a
* JSON text using the put and toString methods. A
* get method returns a value if one can be found, and throws an
* exception if one cannot be found. An opt method returns a
* default value instead of throwing an exception, and so is useful for
* obtaining optional values.
*
* The generic get() and opt() methods return an
* object, which you can cast or query for type. There are also typed
* get and opt methods that do type checking and type
* coercion for you. The opt methods differ from the get methods in that they
* do not throw. Instead, they return a specified value, such as null.
*
* The put methods add or replace values in an object. For
* example,
*
*
* myString = new JSONObject()
* .put("JSON", "Hello, World!").toString();
*
*
* produces the string {"JSON": "Hello, World"}.
*
* The texts produced by the toString methods strictly conform to
* the JSON syntax rules. The constructors are more forgiving in the texts they
* will accept:
*
* - An extra , (comma) may appear just
* before the closing brace.
* - Strings may be quoted with ' (single
* quote).
* - Strings do not need to be quoted at all if they do not begin with a
* quote or single quote, and if they do not contain leading or trailing
* spaces, and if they do not contain any of these characters:
* { } [ ] / \ : , # and if they do not look like numbers and
* if they are not the reserved words true, false,
* or null.
*
*
* @author JSON.org
* @version 2016-08-15
*/
public class JSONObject {
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
* undefined.
*/
private static final class Null {
/**
* A Null object is equal to the null value and to itself.
*
* @param object
* An object to test for nullness.
* @return true if the object parameter is the JSONObject.NULL object or
* null.
*/
@Override
@SuppressWarnings("lgtm[java/unchecked-cast-in-equals]")
public boolean equals(Object object) {
return object == null || object == this;
}
/**
* A Null object is equal to the null value and to itself.
*
* @return always returns 0.
*/
@Override
public int hashCode() {
return 0;
}
/**
* Get the "null" string value.
*
* @return The string "null".
*/
@Override
public String toString() {
return "null";
}
}
/**
* Regular Expression Pattern that matches JSON Numbers. This is primarily used for
* output to guarantee that we are always writing valid JSON.
*/
static final Pattern NUMBER_PATTERN = Pattern.compile("-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?");
/**
* The map where the JSONObject's properties are kept.
*/
private final Map map;
/**
* Retrieves the type of the underlying Map in this class.
*
* @return The class object representing the type of the underlying Map.
*/
public Class