Helper object for parsing formatted JSON values.
sealed class
|
JsonValue
|
implements
|
ICodeOutput
|
||
IEquatable<JsonValue>
|
|||||
ISerializable
|
A formatted JSON value must be written in the following Grammar:
json := value ; array := '[' (value .. ',')? ']' ; member := string ':' value ; object := '{' ((comment)* member .. ',')? '}' ; value := 'false' | 'null' | 'true' | object | array | number | string ; string := '"' (]"\\[ | escape)* '"' ; escape := '\\' ([/tfbn"r\\] | 'u' hexdigit[4]) ; hexdigit := 'a'..'f' | 'A'..'F' | digit ; number := '-'? ('0' | '1'..'9' digit*) ('.' digit+)? (('e' | 'E') ('+' | '-')? digit+)? ; comment := '// ' ]\r\n[* '\r'? '\n' ; digit := '0'..'9' ;
Serialization information about this type.
public
static
readonly
field
|
SerialId
|
||
type
|
ISerialTypeInfo
|
The
null
JSON
value.
public
static
readonly
field
|
Null
|
||
type
|
JsonValue
|
Returns the number of array elements or object members in this JSON value.
public
property
|
Count
{
get
}
|
||
type
|
int32
|
||
value
|
|
The number of aggregated values. |
Returns the array elements of this JSON value.
public
property
|
Elements
{
get
}
|
||
type
|
IVectorConst<JsonValue>
|
||
value
|
|
The
list
of
array
elements.
Will
be
empty
is
IsArray
returns
false .
|
Is
this
JSON
value
of
type
boolean
?
public
property
|
IsBoolean
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
of
type
boolean ,
false
if
not.
|
Is
this
JSON
value
of
type
integer
?
public
property
|
IsInteger
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
of
type
integer ,
false
if
not.
|
Is
this
JSON
value
null
?
public
property
|
IsNull
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
null ,
false
if
not. |
Is
this
JSON
value
of
type
number
?
public
property
|
IsNumber
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
of
type
number ,
false
if
not.
|
Is
this
JSON
value
of
type
object
?
public
property
|
IsObject
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
of
type
object ,
false
if
not.
|
Is
this
JSON
value
of
type
string
?
public
property
|
IsString
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
JSON
value
is
of
type
string ,
false
if
not.
|
Returns the serial type of this object.
public
property
|
SerialType
{
get
}
|
||
type
|
ISerialTypeInfo
|
||
value
|
|
The serial type. | |
implements
|
ISerializable.SerialType
|
Returns the serial data version.
public
property
|
SerialVersion
{
get
}
|
||
type
|
int32
|
||
value
|
|
The serial data version tag. | |
implements
|
ISerializable.SerialVersion
|
Remarks:
An ISerializable implementation is required to support all versions up to the one returned by SerialVersion.
See also:
ISerializable.SerializeCreates a JsonValue from the given text.
public
static
method
|
From
(string text)
|
||
type
|
JsonValue
|
||
params
|
text
|
[not-null]
|
The JSON code. |
returns
|
|
The JsonValue object. |
Creates a new instance of JsonValue from the given file.
public
static
method
|
FromFile
(Path file)
|
||
type
|
JsonValue
|
||
params
|
file
|
[not-null]
|
The file path. |
returns
|
|
The JsonValue object or Null if the file does not exist. |
See also:
ToFileCreates a new instance of JsonValue.
public
constructor
|
JsonValue
()
|
Initializes the state of this object from the given data stream.
public
method
|
Deserialize
(int32 serialVersion,
ISerializer data)
|
||
type
|
ISerializable
|
||
params
|
serialVersion
|
[>=1]
|
The serial data version. |
data
|
[not-null]
|
The serial data stream. | |
returns
|
|
The
deserialized
object.
This
will
typically
be
this ,
but
in
some
circumstances,
another
instance
may
be
returned
(e.g.
singletons).
|
|
implements
|
ISerializable.Deserialize
|
Remarks:
The Deserialize method will be called immediately after the object has been instantiated via its default constructor.
The provided serialVersion number is guaranteed to be equal to or less than the SerialVersion returned by this object (i.e. ISerializable object must provide backwards compatibility).
See also:
ISerializable.SerializeAppends an array element value to this JSON value.
public
method
|
Element
(bool value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
Element
(int32 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
Element
(int64 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
Element
(float64 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
Element
(string value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
Element
(JsonValue value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The element value to append. | |
returns
|
|
this |
Appends an array element value to this JSON value.
public
method
|
ElementAdd
()
|
||
type
|
JsonValue
|
||
returns
|
|
The appended array element value. |
Compares this object with the given one.
[Pure]
|
||||
public
method
|
Equals
(JsonValue other)
|
|||
type
|
bool
|
|||
params
|
other
|
The object to compare to. | ||
returns
|
true
if
this
object
is
equal
to
other,
false
if
not.
|
|||
implements
|
IEquatable.Equals
|
Returns this JSON value as a boolean value.
[Pure]
|
||||
public
method
|
GetBoolean
(bool defaultValue = false)
|
|||
type
|
bool
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
a
boolean
value.
Defaults
to
false .
|
||
returns
|
The boolean value. |
Returns the index-th array element value.
[Pure]
|
||||
public
method
|
GetElement
(int32 index)
|
|||
type
|
JsonValue
|
|||
params
|
index
|
The array element index. | ||
returns
|
|
The element value. Will be Null if this JSON value does not contain the requested value. |
Returns this JSON value as a 32-bit floating point value.
[Pure]
|
||||
public
method
|
GetFloat32
(float32 defaultValue = 0)
|
|||
type
|
float32
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
a
floating
point
value.
Defaults
to
0 .
|
||
returns
|
The floating point value. |
Returns this JSON value as a 64-bit floating point value.
[Pure]
|
||||
public
method
|
GetFloat64
(float64 defaultValue = 0)
|
|||
type
|
float64
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
a
floating
point
value.
Defaults
to
0 .
|
||
returns
|
The floating point value. |
Returns this JSON value as a 32-bit integer value.
[Pure]
|
||||
public
method
|
GetInt32
(int32 defaultValue = 0)
|
|||
type
|
int32
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
an
integer
value.
Defaults
to
0 .
|
||
returns
|
The integer value. |
Returns this JSON value as a 64-bit integer value.
[Pure]
|
||||
public
method
|
GetInt64
(int64 defaultValue = 0)
|
|||
type
|
int64
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
an
integer
value.
Defaults
to
0 .
|
||
returns
|
The integer value. |
Returns the value of the given object member.
[Pure]
|
||||
public
method
|
GetMember
(int32 index)
|
|||
type
|
JsonValue
|
|||
params
|
index
|
The object member index. | ||
returns
|
|
The element value. Will be Null if this JSON value does not contain the requested value. |
Returns the value of the given object member.
[Pure]
|
||||
public
method
|
GetMember
(string name)
|
|||
type
|
JsonValue
|
|||
params
|
name
|
The member name. | ||
returns
|
|
The element value. Will be Null if this JSON value does not contain the requested value. |
Returns the index of the given object member.
[Pure]
|
||||
public
method
|
GetMemberIndex
(string name)
|
|||
type
|
int32
|
|||
params
|
name
|
The member name. | ||
returns
|
The
member
index
of
-1
if
no
such
member
exists. |
Returns this JSON value as a string.
[Pure]
|
||||
public
method
|
GetString
(string defaultValue = null)
|
|||
type
|
string
|
|||
params
|
defaultValue
|
The
default
value
to
return
if
this
JSON
value
cannot
be
interpreted
as
a
string
value.
Defaults
to
null .
|
||
returns
|
The string value. |
Is
this
JSON
value
of
type
array
?
public
method
|
IsArray
(int32 length = -1)
|
||
type
|
bool
|
||
params
|
length
|
The expected array length. If less than zero, the array length is not checked. | |
returns
|
true
if
this
JSON
value
is
of
type
array
and
has
the
expected
length,
false
if
not.
|
Sets an object member of this JSON value.
public
method
|
Member
(string name,
bool value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Sets an object member of this JSON value.
public
method
|
Member
(string name,
int32 value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Sets an object member of this JSON value.
public
method
|
Member
(string name,
int64 value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Sets an object member of this JSON value.
public
method
|
Member
(string name,
float64 value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Sets an object member of this JSON value.
public
method
|
Member
(string name,
string value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Sets an object member of this JSON value.
public
method
|
Member
(string name,
JsonValue value,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
value
|
The member value. | ||
comment
|
Optional comment string. | ||
returns
|
|
this |
Adds an object member to this JSON value.
public
method
|
MemberAdd
(string name,
string comment = null)
|
||
type
|
JsonValue
|
||
params
|
name
|
[not-empty]
|
The member name. |
comment
|
Optional comment string. | ||
returns
|
|
The added member value. |
Serializes the current state of this object to the given data stream.
public
method
|
Serialize
(ISerializer data)
|
||
params
|
data
|
[not-null]
|
The serial data stream. |
implements
|
ISerializable.Serialize
|
See also:
ISerializable.DeserializeSets
the
value
of
this
JSON
value
to
null
.
public
method
|
Set
()
|
||
type
|
JsonValue
|
Sets the value of this JSON value.
public
method
|
Set
(bool value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Sets the value of this JSON value.
public
method
|
Set
(int32 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Sets the value of this JSON value.
public
method
|
Set
(int64 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Sets the value of this JSON value.
public
method
|
Set
(float64 value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Remarks:
The JSON specification does not include infinity or not-a-number. These will be replaced as follows:
Sets the value of this JSON value.
public
method
|
Set
(string value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Sets the value of this JSON value.
public
method
|
Set
(JsonValue value)
|
||
type
|
JsonValue
|
||
params
|
value
|
The new value. | |
returns
|
|
this |
Writes this JSON value to the given file.
public
method
|
ToFile
(Path file)
|
||
params
|
file
|
[not-null]
|
The file path. |
See also:
FromFile
[Pure]
|
||||
public
override
method
|
ToString
()
|
|||
type
|
string
|
public
method
|
ToString
(bool minify)
|
||
type
|
string
|
||
params
|
minify
|
Produces source code by feeding the given source code writer.
public
method
|
WriteSourceCode
(SourceCodeWriter writer,
Context context)
|
||
params
|
writer
|
[not-null]
|
The source code writer to use. |
context
|
[not-null]
|
Context information. | |
implements
|
ICodeOutput.WriteSourceCode
|