public class Json extends Object
| Constructor and Description |
|---|
Json()
Json
|
Json(File file)
Initializes the JSON object for the JSON string stored in the referenced File.
|
Json(String json)
Creates the JSON object from the supplied string.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Object value)
Tests if some key contains the specified value.
|
boolean |
containsKey(String key)
Tests if the specified string is a key in this Json object.
|
Enumeration |
elements()
Returns an enumeration of the values in this Json object.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
Object |
get(String name)
Obtain the value from a name/value pair.
|
boolean |
getBoolean(String name)
Obtain the
boolean from a name/value pair. |
double |
getDouble(String name)
Obtain a
double value from a name/value pair. |
float |
getFloat(String name)
Obtain a
float value from a name/value pair. |
int |
getInt(String name)
Obtain a
int value from a name/value pair. |
long |
getLong(String name)
Obtain a
long value from a name/value pair. |
String |
getString(String name)
Obtain the
string from a name/value pair. |
boolean |
isEmpty()
Determines if the Json object has content.
|
String[] |
keyarray()
Provides a list of the keys or names for all name/value pairs in the Json object.
|
Enumeration |
keys()
Returns an enumeration of the keys in this Json object
|
void |
put(String name,
double v) |
void |
put(String name,
float v) |
void |
put(String name,
int i) |
void |
put(String name,
long i) |
void |
put(String name,
Object value) |
void |
remove(String name) |
void |
save(File file)
Stores the JSON object in string form.
|
void |
save(String filename)
Stores the JSON object in string form.
|
int |
size()
Returns the number of names or keys in this Json object.
|
String |
toString()
Returns a string representation of the object.
|
public Json()
public Json(String json)
json - string containing the JSON text representationpublic Json(File file)
file - File object specifying the initial content.public String toString()
ObjecttoString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object.
public Object get(String name)
name - defines the key/name for the pair.public int getInt(String name) throws NumberFormatException
int value from a name/value pair.name - defines the key/name for the pair.int valueNumberFormatException - if the value is not numeric or contains an illegal numeric character.public long getLong(String name) throws NumberFormatException
long value from a name/value pair.name - defines the key/name for the pair.long valueNumberFormatException - if the value is not numeric or contains an illegal numeric character.public float getFloat(String name) throws NumberFormatException
float value from a name/value pair.name - defines the key/name for the pair.float valueNumberFormatException - if the value is not numeric or contains an illegal numeric character.public double getDouble(String name) throws NumberFormatException
double value from a name/value pair.name - defines the key/name for the pair.double valueNumberFormatException - if the value is not numeric or contains an illegal numeric character.public String getString(String name)
string from a name/value pair.name - defines the key/name for the pair.stringpublic boolean getBoolean(String name)
boolean from a name/value pair.name - defines the key/name for the pair.stringpublic void put(String name, int i)
name - ?i - ?public void put(String name, long i)
name - ?i - ?public void put(String name, float v)
name - ?v - ?public void put(String name, double v)
name - ?v - ?public void remove(String name)
name - ?public Enumeration elements()
public Enumeration keys()
public boolean containsKey(String key)
get()
and check for a null value. This is faster and would return null even
if the key existed but had a JSON_NULL value.key - possible keytrue if and only if the specified string
is a key in this Json object, as determined by the
equals method; false otherwise.public boolean contains(Object value)
value - a value to search fortrue if and only if some key maps to the
value argument in this Json object as
determined by the equals method;
false otherwise.NullPointerException - if the value is nullpublic String[] keyarray()
public int size()
public boolean isEmpty()
TRUE if the object is empty.public void save(String filename)
filename - specifying the destinationpublic void save(File file)
file - File object specifying the destinationprotected void finalize()
throws Throwable
Objectfinalize method to dispose of
system resources or to perform other cleanup.
Any exception thrown by the finalize method causes
the finalization of this object to be halted, but is otherwise
ignored.
The finalize method in Object does
nothing.