Public classes


Scripts/

   JArray
   JBoolean
   JNull
   JNumber
   JSON
   JString
   JValue

Scripts/Attributes/

      ExcludeFromJSONSerializeAttribute
      IncludeToJSONSerializeAttribute

Scripts/Exceptions/

      DeserializeException
      JArgumentException
      JArgumentNullException
      JArrayIndexOutOfRangeException
      JNumberFormatException
      JNumberOverflowException
      JSONKeyAlreadyExistsException
      JSONKeyNotFoundException
      JValueNullException
      JValueTypeException
      ParseException
      ProtectedException
      SerializeException
      UnknownObjectTypeException

Scripts/Settings/

      CreateStringSettings
      DeserializeSettings
      ParseStringSettings
      SerializeSettings


Introduction page

JArray
Derived from JValue


JSON array that may contain any number of JValue objects, including zero (empty array). Objects in array stay in order they are added in to the array. New values can be added, removed and replaced freely.


Constructors

public JArray ()Creates a new empty instance of JArray.
public JArray (IList sourceValues)Creates new JArray object from system list or array of objects.

Indexer

public JValue this [int index]Gets or sets (replaces) the value specified by index.

Properties

public int LengthGets the length of this array.
public JValue[] ValuesGets all the values in this JArray object as system array.

Methods

public void Add (object value)Add new value to end of this array.
public bool[] AsBoolArray ()Get this array as boolean array.
public decimal[] AsDecimalArray ()Get this array as decimal array.
public double[] AsDoubleArray ()Get this array as double-precision float array.
public float[] AsFloatArray ()Get this array as float array.
public int[] AsIntArray ()Get this array as integer array.
public JArray[] AsJArrayArray ()Get this array as arrays.
public JSON[] AsJSONArray ()Get this array as JSON array.
public List AsList ()Gets the whole JArray object as system list.
public long[] AsLongArray ()Get this array as long array.
public string[] AsStringArray ()Get this array as string array.
public void Clear ()Remove all the values from this JArray, leaving it empty.
public bool ContainsValue (object valueToSearch)Check whatever this JArray object contains specified value.
public string CreatePrettyString ()Turns this JSON array to string JSON formatted, but easily human readable string.
public override string CreateString ()Turns this JSON array to single JSON formatted string.
public override string CreateString (CreateStringSettings settings)Turns this JSON array to single JSON formatted string using specified settings.
public void DebugInEditor (string debugName)Adds this JArray object to editor debug window so content of JSON object can be followed in Unity editor when application is running.
public T Deserialize<T> ()Deserialize this JArray to object, using default settings.
public T Deserialize<T> (DeserializeSettings deserializeSettings)Deserialize this JArray to object, using specified settings.
public override bool Equals (object anotherObject)Test if another object equals to this object.
public JValue Get (int index)Get value from specific index in this array.
public bool GetBool (int index)Gets C# bool value from specific index in this array.
public float GetFloat (int index)Gets floating point number from specific index in this array.
public int GetInt (int index)Gets integer number from specific index in this array.
public JArray GetJArray (int index)Gets JArray value from specific index in this array.
public JNumber GetJNumber (int index)Gets JNumber value from specific index in this array.
public JSON GetJSON (int index)Gets JSON value from specific index in this array.
public string GetString (int index)Gets C# string value from specific index in this array.
public void InsertAt (int index, object value)Insert new value to specific index.
public bool IsEmpty ()Check whatever this JArray object is empty (length is 0).
public bool IsJNull (int index)Check if value in specified index is JNull.
public bool IsProtected ()Check whatever this JArray is protected (read only).
public void RemoveAt (int index)Remove value from specific index.
public void RemoveValue (object valueToRemove)Removes first instance of value that equals to parameter value.
public void ReplaceAt (int index, object value)Replace value to specific index in this array.
public void SetProtected ()Sets this JArray and all its childen protected (read only).
public override string ToString ()Returns compact information of this JArray object as string, for debug purposes.
internal bool deepContainsObject (JValue obj)Check whatever this JArray object or recursively any of child objects contains specified object.

Static Methods

public static JArray ParseString (string jsonArrayInSingleString)Turns JSON array formatted string to new JSON array object.
public static JArray ParseString (string jsonArrayInSingleString, string debugIDForExceptions)Turns JSON array formatted string to new JSON array object.
public static JArray ParseString (string jsonArrayInSingleString, ParseStringSettings parseStringSettings)Turns JSON array formatted string to new JSON array object, using specified settings.
public static JArray Serialize (object objectToSerialize)Serialize object to new JArray object, using default settings.
public static JArray Serialize (object objectToSerialize, SerializeSettings serializeSettings)Serialize object to JArray object, using specific settings.

Constructors

public JArray ()

Creates a new empty instance of JArray.


public JArray (IList sourceValues)

Creates new JArray object from system list or array of objects. Note that values in dictionary need to be basic c# objects like string, booleans, numbers, or another lists or dictionaries. To turn other classes to JSON object, or for more flexible options, consider using static JArray.Serialize() method.

ParameterssourceValuesSource values. Each element have to be either JValue, or any basic c# object that can be changed to JValue.

ExceptionsJArgumentExceptionIf any exceptions occurs when trying to turn parameter list to new JArray object.
 JArgumentNullExceptionIf parameter is null.
 UnknownObjectTypeExceptionIf any value in parameter array/list is unsupported type.


Indexer

public JValue this [int index]

Gets or sets (replaces) the value specified by index.

ParametersindexIndex of the value to get or set.

ValueAny JValue object, can not be null but can be JNull.


Properties

public int Length

Gets the length of this array.

ValueArray length.


public JValue[] Values

Gets all the values in this JArray object as system array. You can use this to loop through all the values in this JArray, for example:
foreach (JValue value in jarray.Values) {...}

Array of returned values is shallow copy of internal array of this JArray object. This means you can add or remove values from this JArray while looping through the values. For example, removing all the number elements from the JArray:

foreach (JValue value in jarray.Values) {
if (value is JNumber) {
jarray.RemoveValue(value);
}
}

ValueAll the values in this JArray object.


Methods

public void Add (object value)

Add new value to end of this array.

ParametersvalueValue to add. Either any JValue, or any basic c# object that can be changed to JValue (string, bool, numbers and null).

ExceptionsJArgumentExceptionIf adding parameter value to this JArray would cause circular JSON, meaning this JArray or recursively any of its children would contain this JArray itself.
 ProtectedExceptionIf this JArray object is set protected (read only).
 UnknownObjectTypeExceptionIf parameter value is unsupported type.


public bool[] AsBoolArray ()

Get this array as boolean array. All the values in this array must be booleans.

ReturnsArray of bools.

ExceptionsJValueTypeExceptionIf any value in array is other than boolean.


public decimal[] AsDecimalArray ()

Get this array as decimal array. All the values in this array must be numbers inside decimal range.

ReturnsArray of decimals.

ExceptionsJValueTypeExceptionIf any value in array is other than number.


public double[] AsDoubleArray ()

Get this array as double-precision float array. All the values in this array must be numbers inside double range.

ReturnsArray of doubles.

ExceptionsJValueTypeExceptionIf any value in array is other than number.


public float[] AsFloatArray ()

Get this array as float array. All the values in this array must be numbers inside float range.

ReturnsArray of floats.

ExceptionsJValueTypeExceptionIf any value in array is other than number.


public int[] AsIntArray ()

Get this array as integer array. All the values in this array must be numbers inside integer range.

ReturnsArray of integers.

ExceptionsJValueTypeExceptionIf any value in array is other than number.


public JArray[] AsJArrayArray ()

Get this array as arrays. All the values in this array must be other arrays or nulls.

ReturnsArray of JArray elements. May contains null elements, but returning array itself can not be null.

ExceptionsJValueTypeExceptionIf any value in array is other than array or null.


public JSON[] AsJSONArray ()

Get this array as JSON array. All the values in this array must be JSON or JNull objects.

ReturnsArray of JSON elements. May contains null elements, but returning array itself can not be null.

ExceptionsJValueTypeExceptionIf any value in array is other than JSON object or null.


public List AsList ()

Gets the whole JArray object as system list. This is recursive, so if this list contains other lists or JSON objects, those will be also changed to system objects.

ReturnsList that doesn't contain any TotalJSON objects on any level.


public long[] AsLongArray ()

Get this array as long array. All the values in this array must be numbers inside long range.

ReturnsArray of longs.

ExceptionsJValueTypeExceptionIf any value in array is other than number.


public string[] AsStringArray ()

Get this array as string array. All the values in this array must be strings or nulls.

ReturnsArray of strings. May contains null elements, but returning array itself can not be null.

ExceptionsJValueTypeExceptionIf any value in array is other than string or null.


public void Clear ()

Remove all the values from this JArray, leaving it empty.

ExceptionsProtectedExceptionIf this JArray object is set protected (read only).


public bool ContainsValue (object valueToSearch)

Check whatever this JArray object contains specified value.

ParametersvalueToSearchValue to look for.

Returnstrue if this JArray contains 'valueToSearch', false otherwise.

ExceptionsUnknownObjectTypeExceptionIf parameter value is unsupported type and therefore can not exist in this JArray.


public string CreatePrettyString ()

Turns this JSON array to string JSON formatted, but easily human readable string. This output is not as tightly packed as string returned by CreateString() but contains all the same data and is still completely valid JArray.

This method is just a shortcut for doing:

CreateStringSettings createStringSettings = new CreateStringSettings();
createStringSettings.HumanReadable = true;
string output = CreateString(createStringSettings);

ReturnsThis array as JSON formatted string, containing only basic ascii characters between [32..126], line feeds and tabs.


public override string CreateString ()

Turns this JSON array to single JSON formatted string. String always starts with character '[' and ends to character ']'

Note that for large JArray objects output may be also very long. For debugging purposes, consider also .

ReturnsThis array as JSON formatted string, containing only basic ascii characters between [32..126] without line feeds.


public override string CreateString (CreateStringSettings settings)

Turns this JSON array to single JSON formatted string using specified settings. String always starts with character '[' and ends to character ']'

ReturnsThis array as JSON formatted string.


public void DebugInEditor (string debugName)

Adds this JArray object to editor debug window so content of JSON object can be followed in Unity editor when application is running. Choose "Window" -> "Total JSON" -> "JSON Runtime Debug" from Unity editor menu top open this window.

Calling this method outside Unity editor doesn't do anything.

ParametersdebugNameName of this object in debug window.


public T Deserialize<T> ()

Deserialize this JArray to object, using default settings.

Type parametersTType of object that can hold all the content of this JArray.

ReturnsObject of wanted type.

ExceptionsDeserializeExceptionIf any exceptions occurs when trying to deserialize this JArray to object.


public T Deserialize<T> (DeserializeSettings deserializeSettings)

Deserialize this JArray to object, using specified settings.

Type parametersTType of object that can hold all the content of this JArray.

ParametersdeserializeSettingsSettings used for deserialization.

ReturnsObject of wanted type.

ExceptionsDeserializeExceptionIf any exceptions occurs when trying to deserialize this JArray to object.


public override bool Equals (object anotherObject)

Test if another object equals to this object. Always returns false if parameter object is null or it is not instance of JArray. Two JArray objects are equal if both contains same amount of elements and every element in same indexes equals to each other.

ParametersanotherObjectAnother object that is compared to this one.

ReturnsTrue if objects are equal, false otherwise.


public JValue Get (int index)

Get value from specific index in this array.

ParametersindexIndex of element to get.

ReturnsJValue object from index. Returned value is never null, but it can be JNull.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.


public bool GetBool (int index)

Gets C# bool value from specific index in this array. This method will cause exception if value is anything else than JBoolean.

ParametersindexArray index where to get bool value.

ReturnsC# bool value.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JValueTypeExceptionIf value in index is not JBoolean.


public float GetFloat (int index)

Gets floating point number from specific index in this array. This method will cause exception if key/value pair doesn't exist, value is not number or it is outside float range.


This method is for convenience. It is equal to jArray.GetJNumber(index).AsFloat();
If there is need to get number value from JArray in some very specific format, use GetJNumber(index) and
then use methods provided by JNumber class, for example jArray.GetJNumber(index).AsDecimal();

ParametersindexArray index where to get float value.

ReturnsC# float value.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JNumberOverflowExceptionIf number stored to this JNumber doesn't fit in float.
 JValueNullExceptionIf value mapped to this key is null.
 JValueTypeExceptionIf value in index is not JNumber.


public int GetInt (int index)

Gets integer number from specific index in this array. This method will cause exception if key/value pair doesn't exist, value is not number or it is outside int range.


This method is for convenience. It is equal to jArray.GetJNumber(index).AsInt();
If there is need to get number value from JArray in some very specific format, use GetJNumber(index) and
then methods provided by JNumber class, for example jArray.GetJNumber(index).AsULong();

ParametersindexArray index where to get int value.

ReturnsC# int value.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JNumberFormatExceptionIf number stored to this JNumber is floating point number.
 JNumberOverflowExceptionIf number stored to this JNumber doesn't fit in int.
 JValueNullExceptionIf value mapped to this key is null.
 JValueTypeExceptionIf value in index is not JNumber.


public JArray GetJArray (int index)

Gets JArray value from specific index in this array. This method will cause exception if value is anything else than JArray or JNull.

ParametersindexArray index where to get JArray value.

ReturnsJArray or null if value at index is JNull.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JValueTypeExceptionIf value in index is not JArray or JNull.


public JNumber GetJNumber (int index)

Gets JNumber value from specific index in this array. This method will cause exception if value is anything else than JNumber or JNull.

ParametersindexArray index where to get JNumber value.

ReturnsJNumber or null if value at index is JNull.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JValueTypeExceptionIf value in index is not JNumber or JNull.


public JSON GetJSON (int index)

Gets JSON value from specific index in this array. This method will cause exception if value is anything else than JSON or JNull.

ParametersindexArray index where to get JSON value.

ReturnsJSON or null if value at index is JNull.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JValueTypeExceptionIf value in index is not JSON or JNull.


public string GetString (int index)

Gets C# string value from specific index in this array. This method will cause exception if value is anything else than JString or JNull.

ParametersindexArray index where to get string value.

ReturnsC# string or null if value at index is JNull.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 JValueTypeExceptionIf value in index is not JString or JNull.


public void InsertAt (int index, object value)

Insert new value to specific index. Just like when using Add method, nothing is replaced and array length will be one more after this. Index may be equal to current array length, in that case this method works exactly as Add(JValue)

ParametersindexIndex in array where to insert new value.
 valueValue to insert. Value can't be null but it can be JNull.

ExceptionsJArgumentExceptionIf adding parameter value to this JArray would cause circular JSON, meaning this JArray or recursively any of its children would contain this JArray itself.
 JArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than this JArray length.
 ProtectedExceptionIf this JArray object is set protected (read only).
 UnknownObjectTypeExceptionIf parameter value is unsupported type.


public bool IsEmpty ()

Check whatever this JArray object is empty (length is 0).

Returnstrue if this array is empty, false otherwise.


public bool IsJNull (int index)

Check if value in specified index is JNull.

ParametersindexArray index to check.

Returnstrue value in index is JNull, false otherwise.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than equal to this JArray length.


public bool IsProtected ()

Check whatever this JArray is protected (read only). If it is, it also means that all its childen are protected, but nothing can be assumed of parents of this object.

Returnstrue if this object is protected, false otherwise


public void RemoveAt (int index)

Remove value from specific index. After this array length will be one less than before.

ParametersindexIndex in array where to remove the value.

ExceptionsJArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 ProtectedExceptionIf this JArray object is set protected (read only).


public void RemoveValue (object valueToRemove)

Removes first instance of value that equals to parameter value.

ParametersvalueToRemoveValue to be removed.

ExceptionsJArgumentExceptionIf can not found any value matching the parameter.
 ProtectedExceptionIf this JArray object is set protected (read only).
 UnknownObjectTypeExceptionIf parameter value is unsupported type and therefore can not exist in this JArray.


public void ReplaceAt (int index, object value)

Replace value to specific index in this array. Array length won't change. This can only replace existing values and can not be used to add new values to array. Trying to set value outside array size will cause exception.

ParametersindexIndex in array where value should be replaced.
 valueValue to set. Either any JValue, or any basic c# object that can be changed to JValue (string, bool, numbers and null).

ExceptionsJArgumentExceptionIf adding parameter value to this JArray would cause circular JSON, meaning this JArray or recursively any of its children would contain this JArray itself.
 JArrayIndexOutOfRangeExceptionIf parameter index is negative, or more than or equal to this JArray length.
 ProtectedExceptionIf this JArray object is set protected (read only).
 UnknownObjectTypeExceptionIf parameter value is unsupported type.


public void SetProtected ()

Sets this JArray and all its childen protected (read only). New values can't be added and old values replaced or removed.

Typically this is called only for top level JSON. Protecetion can't be cancelled, once it is set, it will stay.


public override string ToString ()

Returns compact information of this JArray object as string, for debug purposes.

When you want to get all content of this JArray object in JSON formatted string, use .

ReturnsSingle string with information of this JArray object.


internal bool deepContainsObject (JValue obj)

Check whatever this JArray object or recursively any of child objects contains specified object.

ParametersobjObject to look for.

Returnstrue if this exact 'obj' object exists somewhere in JSON tree hierarchy starting from this object, false otherwise.


Static Methods

public static JArray ParseString (string jsonArrayInSingleString)

Turns JSON array formatted string to new JSON array object.

ParametersjsonArrayInSingleStringSource string where to read array.

ReturnsNew JSON array object.

ExceptionsJArgumentNullExceptionIf parameter string is null.
 ParseExceptionIf input string can not be parsed to JArray.


public static JArray ParseString (string jsonArrayInSingleString, string debugIDForExceptions)

Turns JSON array formatted string to new JSON array object. Debug ID is added to this parse operation, which will be added to any possible exceptions that may occur during parse.

This method is for convenience. This method will create new ParseStringSettings object and set value for DebugIDForExceptions,
then call ParseString(string jsonArrayInSingleString, ParseStringSettings parseStringSettings) method.

ParametersjsonArrayInSingleStringSource string where to read array.
 debugIDForExceptionsID that will be added to any possible exception message. This value have no effect to resulting JArray object.

ReturnsNew JSON array object.

ExceptionsJArgumentNullExceptionIf parameter string is null.
 ParseExceptionIf input string can not be parsed to JArray.


public static JArray ParseString (string jsonArrayInSingleString, ParseStringSettings parseStringSettings)

Turns JSON array formatted string to new JSON array object, using specified settings.

ParametersjsonArrayInSingleStringSource string where to read array.
 parseStringSettingsSettings to be used when parsing the string.

ReturnsNew JSON array object.

ExceptionsJArgumentNullExceptionIf parameter string or settings object is null.
 ParseExceptionIf input string can not be parsed to JArray.


public static JArray Serialize (object objectToSerialize)

Serialize object to new JArray object, using default settings.

ParametersobjectToSerializeObject that can be serialized to JArray such as list or system array.

ReturnsJArray object containing items from parameter object.

ExceptionsSerializeExceptionIf any exceptions occurs when trying to serialize object to new JArray.


public static JArray Serialize (object objectToSerialize, SerializeSettings serializeSettings)

Serialize object to JArray object, using specific settings.

ParametersobjectToSerializeObject that can be serialized to JArray such as list or system array.
 serializeSettingsSettings used for serialization.

ReturnsJArray object containing items from parameter object.

ExceptionsSerializeExceptionIf any exceptions occurs when trying to serialize object to new JArray.