Skip to content
robbyxp1 edited this page Aug 19, 2024 · 9 revisions

JArray Class

JSON Array object, holding a ordered list of JTokens

public class JArray : QuickJSON.JToken

Inheritance System.Object 🡒 JToken 🡒 JArray


Constructors


JArray.JArray() Constructor

Create an empty JArray

public JArray();


JArray.JArray(object[]) Constructor

Create a JArray with these items as its data

public JArray(params object[] data);
Parameters

data System.Object[]
List of data to store in JArray


JArray.JArray(JToken) Constructor

Create an array with a single item

public JArray(QuickJSON.JToken othertoken);
Parameters

othertoken JToken
JToken to store in array


JArray.JArray(IEnumerable) Constructor

Create a JArray from items in an IEnumerable

public JArray(System.Collections.IEnumerable data);
Parameters

data System.Collections.IEnumerable
IEnumerable with data itema


Properties


JArray.Count Property

Get number of JArray items

public override int Count { get; }
Property Value

System.Int32


JArray.this[int] Property

Access JToken by int indexer
Returns JToken found by indexer

public QuickJSON.JToken this[int element] { get; set; }
Parameters

element System.Int32

Property Value

JToken

Exceptions

System.ArgumentOutOfRangeException
If indexer is out of range


JArray.this[object] Property

Access JToken by int indexer
Returns JToken found by indexer, or null if not present, indexer out of range or indexer is not an int

public override QuickJSON.JToken this[object key] { get; set; }
Parameters

key System.Object

Property Value

JToken

Exceptions

System.ArgumentOutOfRangeException
If indexer is out of range on set

System.InvalidCastException
If indexer is not of type int on set


Methods


JArray.Add<T>(T) Method

Add type T to the end of the array. T must be convertable to a JToken - see JToken Implicit conversions

public override void Add<T>(T value);
Type parameters

T

Parameters

value T


JArray.Add(JToken) Method

Add a JToken to the end of the array

public override void Add(QuickJSON.JToken o);
Parameters

o JToken


JArray.AddRange<T>(IEnumerable<T>) Method

Add a range of items of type T to the end of the array. T must be convertable to a JToken - see JToken Implicit conversions

public override void AddRange<T>(System.Collections.Generic.IEnumerable<T> values);
Type parameters

T

Parameters

values System.Collections.Generic.IEnumerable<T>


JArray.AddRange(IEnumerable<JToken>) Method

Add a range of JTokens to the end of the array

public override void AddRange(System.Collections.Generic.IEnumerable<QuickJSON.JToken> o);
Parameters

o System.Collections.Generic.IEnumerable<JToken>


JArray.Bool() Method

Convert the JTokens in the array to bool and return a list of bools.
Both true/false bool array and integer arrays (0=false, otherwise true) are acceptable

public System.Collections.Generic.List<bool> Bool();
Returns

System.Collections.Generic.List<System.Boolean>

Exceptions

System.InvalidCastException
If any items are not numbers or true or false


JArray.Clear() Method

Clear the array

public override void Clear();


JArray.DateTime() Method

Convert the JTokens in the array to DateTime and return a list of DateTimes.

public System.Collections.Generic.List<System.DateTime> DateTime();
Returns

System.Collections.Generic.List<System.DateTime>

Exceptions

System.InvalidCastException
If any items are not DateTimes


JArray.Double() Method

Convert the JTokens in the array to doubles and return a list of doubles.

public System.Collections.Generic.List<double> Double();
Returns

System.Collections.Generic.List<System.Double>

Exceptions

System.InvalidCastException
If any items are not numbers


JArray.Find<T>(Predicate<JToken>) Method

Find a JToken in the array according the the predicate and convert the value to type T. Return null if not found. If found, type must convert

public T Find<T>(System.Predicate<QuickJSON.JToken> predicate);
Type parameters

T
Type to convert the value to

Parameters

predicate System.Predicate<JToken>

Returns

T

Exceptions

System.InvalidOperationException
If JToken is not compatible with conversion.


JArray.Find(Predicate<JToken>) Method

Find a token in the array according the the predicate. Return null if not found

public QuickJSON.JToken Find(System.Predicate<QuickJSON.JToken> predicate);
Parameters

predicate System.Predicate<JToken>

Returns

JToken


JArray.First() Method

Get the first JToken

public override QuickJSON.JToken First();
Returns

JToken

Exceptions

System.ArgumentOutOfRangeException
If no items are present


JArray.FirstOrDefault() Method

Get the first JToken or null if no elements are in the list

public override QuickJSON.JToken FirstOrDefault();
Returns

JToken


JArray.Float() Method

Convert the JTokens in the array to floats and return a list of floats.

public System.Collections.Generic.List<float> Float();
Returns

System.Collections.Generic.List<System.Single>

Exceptions

System.InvalidCastException
If any items are not numbers


JArray.IndexOf(JToken) Method

Index of JToken

public int IndexOf(QuickJSON.JToken tk);
Parameters

tk JToken

Returns

System.Int32


JArray.Int() Method

Convert the JTokens in the array to int and return a list of ints. Truncation of value may occur.

public System.Collections.Generic.List<int> Int();
Returns

System.Collections.Generic.List<System.Int32>

Exceptions

System.InvalidCastException
If any items are not numbers


JArray.Last() Method

Get the last JToken

public override QuickJSON.JToken Last();
Returns

JToken

Exceptions

System.ArgumentOutOfRangeException
If no items are present


JArray.LastOrDefault() Method

Get the last JToken or null if no elements are in the list

public override QuickJSON.JToken LastOrDefault();
Returns

JToken


JArray.Long() Method

Convert the JTokens in the array to longs and return a list of longs. Truncation of value may occur.

public System.Collections.Generic.List<long> Long();
Returns

System.Collections.Generic.List<System.Int64>

Exceptions

System.InvalidCastException
If any items are not numbers


JArray.Parse(string, ParseOptions) Method

Parse the JSON string presuming it will return an JArray

public static QuickJSON.JArray Parse(string text, QuickJSON.JToken.ParseOptions flags=QuickJSON.JToken.ParseOptions.None);
Parameters

text System.String
Text to parse

flags ParseOptions
Parsing flags, default None

Returns

JArray
JArray or null if parse fails or does not return a JArray

Exceptions

JsonException
Thrown on error if parse flags indicate exception required. Error will be in exception error value


JArray.Parse(string, string, ParseOptions) Method

Parse the JSON string presuming it will return an JArray

public static QuickJSON.JArray Parse(string text, out string error, QuickJSON.JToken.ParseOptions flags);
Parameters

text System.String
Text to parse

error System.String
Null if no error, else error string

flags ParseOptions
Parsing flags

Returns

JArray
JArray or null if parse fails or does not return a JArray

Exceptions

JsonException
Thrown on error if parse flags indicate exception required. Error will be in exception Error value


JArray.ParseThrowCommaEOL(string) Method

Parse the JSON string presuming it will return an JArray
Parsing flags are set to AllowTrailingCommas | CheckEOL | ThrowOnError

public static QuickJSON.JArray ParseThrowCommaEOL(string text);
Parameters

text System.String
Text to parse

Returns

JArray
JArray

Exceptions

JsonException
Thrown on error. Error will be in exception Error value


JArray.RemoveAt(int) Method

Remove JToken at index

public void RemoveAt(int index);
Parameters

index System.Int32

Exceptions

System.ArgumentOutOfRangeException
If index is out of range


JArray.RemoveRange(int, int) Method

public void RemoveRange(int index, int count);
Parameters

index System.Int32

count System.Int32

Exceptions

System.ArgumentOutOfRangeException
If index is out of range


JArray.String() Method

Convert the JTokens in the array to strings and return a list of strings.
Any non strings are inserted into the list as null

public System.Collections.Generic.List<string> String();
Returns

System.Collections.Generic.List<System.String>


JArray.TryGetValue(int, JToken) Method

Get a JToken at this index.

public bool TryGetValue(int index, out QuickJSON.JToken token);
Parameters

index System.Int32
Index of item

token JToken
Where to store the found JToken

Returns

System.Boolean
If index out of range, return false (null in token), else return true (token has found item)

Clone this wiki locally