TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class JsonValue in Tinman.Core.Formatting

Helper object for parsing formatted JSON values.

sealed class JsonValue implements ICodeOutput
  IEquatable<JsonValue>
  ISerializable

Remarks

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

SerialId

Serialization information about this type.

public static readonly field SerialId
type ISerialTypeInfo

Public / Constants

Null

The null JSON value.

public static readonly field Null
type JsonValue

Public / Attributes

Count

Returns the number of array elements or object members in this JSON value.

public property Count { get }
type int32
value [>=0] The number of aggregated values.

Elements

Returns the array elements of this JSON value.

public property Elements { get }
type IVectorConst<JsonValue>
value [not-null] The list of array elements. Will be empty is IsArray returns false.

IsBoolean

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.

IsInteger

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.

IsNull

Is this JSON value null?

public property IsNull { get }
type bool
value true if this JSON value is null, false if not.

IsNumber

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.

IsObject

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.

IsString

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.

SerialType

Returns the serial type of this object.

public property SerialType { get }
type ISerialTypeInfo
value [not-null] The serial type.
implements ISerializable.SerialType

SerialVersion

Returns the serial data version.

public property SerialVersion { get }
type int32
value [>=1] 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.Serialize
ISerializable.Deserialize

Public / Constructors

From

Creates a JsonValue from the given text.

public static method From (string text)
type JsonValue
params text [not-null] The JSON code.
returns [not-null] The JsonValue object.

FromFile

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 [not-null] The JsonValue object or Null if the file does not exist.

See also:

ToFile

JsonValue

Creates a new instance of JsonValue.

public constructor JsonValue ()

Public / Methods

Deserialize

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 [not-null] 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.Serialize
ISerializable.SerialVersion

Element

Appends an array element value to this JSON value.

public method Element (bool value)
type JsonValue
params value The element value to append.
returns [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] this

ElementAdd

Appends an array element value to this JSON value.

public method ElementAdd ()
type JsonValue
returns [not-null] The appended array element value.

Equals

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

GetBoolean

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.

GetElement

Returns the index-th array element value.

[Pure]
public method GetElement (int32 index)
type JsonValue
params index The array element index.
returns [not-null] The element value. Will be Null if this JSON value does not contain the requested value.

GetFloat32

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.

GetFloat64

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.

GetInt32

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.

GetInt64

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.

GetMember

Returns the value of the given object member.

[Pure]
public method GetMember (int32 index)
type JsonValue
params index The object member index.
returns [not-null] 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 [not-null] The element value. Will be Null if this JSON value does not contain the requested value.

GetMemberIndex

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.

GetString

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.

IsArray

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.

Member

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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] this

MemberAdd

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 [not-null] The added member value.

Serialize

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.Deserialize
ISerializable.SerialVersion

Set

Sets 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 [not-null] this

Sets the value of this JSON value.

public method Set (int32 value)
type JsonValue
params value The new value.
returns [not-null] this

Sets the value of this JSON value.

public method Set (int64 value)
type JsonValue
params value The new value.
returns [not-null] this

Sets the value of this JSON value.

public method Set (float64 value)
type JsonValue
params value The new value.
returns [not-null] 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 [not-null] this

Sets the value of this JSON value.

public method Set (JsonValue value)
type JsonValue
params value The new value.
returns [not-null] this

ToFile

Writes this JSON value to the given file.

public method ToFile (Path file)
params file [not-null] The file path.

See also:

FromFile

ToString

[Pure]
public override method ToString ()
type string

public method ToString (bool minify)
type string
params minify

WriteSourceCode

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