public class JsonNumber extends JsonValue
Constructor and Description |
---|
JsonNumber(java.lang.String string)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
double |
asDouble()
Returns this JSON value as a
double value, assuming that this value represents a
JSON number. |
float |
asFloat()
Returns this JSON value as a
float value, assuming that this value represents a
JSON number. |
int |
asInt()
Returns this JSON value as an
int value, assuming that this value represents a
JSON number that can be interpreted as Java int . |
long |
asLong()
Returns this JSON value as a
long value, assuming that this value represents a
JSON number that can be interpreted as Java long . |
boolean |
equals(java.lang.Object object)
Indicates whether some other object is "equal to" this one according to the contract specified
in
Object.equals(Object) . |
int |
hashCode() |
boolean |
isNumber()
Detects whether this value represents a JSON number.
|
java.lang.String |
toString()
Returns the JSON string for this value in its minimal form, without any additional whitespace.
|
public JsonNumber(java.lang.String string)
string
- valuepublic java.lang.String toString()
JsonValue
Json.parse(String)
and to
create a value that is equal to this object.public boolean isNumber()
JsonValue
public int asInt()
JsonValue
int
value, assuming that this value represents a
JSON number that can be interpreted as Java int
. If this is not the case, an
exception is thrown.
To be interpreted as Java int
, the JSON number must neither contain an exponent
nor a fraction part. Moreover, the number must be in the Integer
range.
public long asLong()
JsonValue
long
value, assuming that this value represents a
JSON number that can be interpreted as Java long
. If this is not the case, an
exception is thrown.
To be interpreted as Java long
, the JSON number must neither contain an exponent
nor a fraction part. Moreover, the number must be in the Long
range.
public float asFloat()
JsonValue
float
value, assuming that this value represents a
JSON number. If this is not the case, an exception is thrown.
If the JSON number is out of the Float
range, Float.POSITIVE_INFINITY
or
Float.NEGATIVE_INFINITY
is returned.
public double asDouble()
JsonValue
double
value, assuming that this value represents a
JSON number. If this is not the case, an exception is thrown.
If the JSON number is out of the Double
range, Double.POSITIVE_INFINITY
or
Double.NEGATIVE_INFINITY
is returned.
public boolean equals(java.lang.Object object)
JsonValue
Object.equals(Object)
.
Two JsonValues are considered equal if and only if they represent the same JSON text. As a consequence, two given JsonObjects may be different even though they contain the same set of names with the same values, but in a different order.