Skip to content

JObject

robbyxp1 edited this page Feb 9, 2025 · 11 revisions

JObject Class

JSON Object, holding a list of JSON JTokens referenced by property names

public class JObject : QuickJSON.JToken,
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, QuickJSON.JToken>>,
System.Collections.IEnumerable

Inheritance System.Object 🡒 JToken 🡒 JObject

Implements System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String,JToken>>, System.Collections.IEnumerable


Constructors


JObject.JObject() Constructor

Makes an empty JObject

public JObject();


JObject.JObject(JObject) Constructor

Makes an clone of another JObject

public JObject(QuickJSON.JObject other);
Parameters

other JObject


JObject.JObject(IDictionary) Constructor

Makes an JObject with property names and values from an IDictionary

public JObject(System.Collections.IDictionary dict);
Parameters

dict System.Collections.IDictionary


Properties


JObject.Count Property

Get number of properties

public override int Count { get; }
Property Value

System.Int32


JObject.this[object] Property

Access JToken by string property key
Returns JToken found by property key, or null if not present or indexer is not a string

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

key System.Object

Property Value

JToken

Exceptions

System.InvalidCastException
If name is not of type string on set


JObject.this[string] Property

Access JToken by string indexer
Returns JToken found by indexer, or null if not present

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

key System.String

Property Value

JToken


Methods


JObject.Add<T>(string, T) Method

Add a JToken with this property name. Will overwrite any existing property

public override void Add<T>(string key, T o);
Type parameters

T

Parameters

key System.String

o T


JObject.Add(string, JToken) Method

Add a JToken with this property name. Will overwrite any existing property

public override void Add(string key, QuickJSON.JToken value);
Parameters

key System.String

value JToken


JObject.Clear() Method

Clear all properties

public override void Clear();


JObject.Contains(string) Method

Does the JObject contain property name

public override bool Contains(string name);
Parameters

name System.String

Returns

System.Boolean


JObject.Contains(string[]) Method

Does the JObject contain any of these properties, if so return first one found, else return null

public QuickJSON.JToken Contains(string[] ids);
Parameters

ids System.String[]

Returns

JToken


JObject.ContainsAllOfThese(string[]) Method

Does the JObject contain all the listed properties

public bool ContainsAllOfThese(params string[] name);
Parameters

name System.String[]

Returns

System.Boolean


JObject.ContainsAnyOf(string[]) Method

Does the JObject contain one of these?

public bool ContainsAnyOf(params string[] name);
Parameters

name System.String[]

Returns

System.Boolean


JObject.ContainsIndexOf(JToken, string[]) Method

Does the JObject contain one of these? -1 no, else first one found.

public int ContainsIndexOf(out QuickJSON.JToken ret, params string[] name);
Parameters

ret JToken

name System.String[]

Returns

System.Int32


JObject.ContainsIndexOf(string[]) Method

Does the JObject contain one of these? -1 no, else first one found.

public int ContainsIndexOf(params string[] name);
Parameters

name System.String[]

Returns

System.Int32


JObject.Filter(JObject, string) Method

Filter this object into a return object.
Allowed fields are a set of object key/value pairs with the value set to:

   Boolean true/false: direct allow/disallow of any type with this field name  
   JArray containing one JOBJECT: item is an array of objects, with the allowed fields in that object listed:  
       ["name"] = new JArray  
           {   new JObject  
               {  
                   ["Null"] = true,  
                   ["Star"] = true,  
                   ["Planet"] = true,  
                   ["Ring"] = true  
               } }  
        or  
        ["name"] = "[]" - Allow anything in an array  
   JObject: allow an object with these fields present if boolean is true.  
         ["name"] = new JObject  
         {  
             ["Rock"] = true,  
             ["Metal"] = true,  
         },  
public QuickJSON.JObject Filter(QuickJSON.JObject allowedFields, string path="");
Parameters

allowedFields JObject
A JObject of allowed fields to keep

path System.String
path is used to track the object names through the heirachy for diagnostics purposes only. Do not set.

Returns

JObject
Clone of JToken with allowed fields only


JObject.First() Method

Get the first JToken

public override QuickJSON.JToken First();
Returns

JToken

Exceptions

System.ArgumentOutOfRangeException
If no items are present


JObject.FirstOrDefault() Method

Get the first JToken or null if no properties are present

public override QuickJSON.JToken FirstOrDefault();
Returns

JToken


JObject.GetEnumerator() Method

Key Value Pair Enumerator

public System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<string,QuickJSON.JToken>> GetEnumerator();
Returns

System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.String,JToken>>

Implements GetEnumerator(), GetEnumerator()


JObject.Last() Method

Get the last JToken

public override QuickJSON.JToken Last();
Returns

JToken

Exceptions

System.ArgumentOutOfRangeException
If no items are present


JObject.LastOrDefault() Method

Get the last JToken or null if no properties are present

public override QuickJSON.JToken LastOrDefault();
Returns

JToken


JObject.Merge(JObject, bool) Method

Merge two objects together, with overwrite protection

public void Merge(QuickJSON.JObject other, bool allowoverwrite=true);
Parameters

other JObject
Other JObject to merge into this

allowoverwrite System.Boolean
Allows overwriting of this object members with other


JObject.Parse(string, ParseOptions) Method

Parse the JSON string presuming it will return an JObject

public static QuickJSON.JObject 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

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

Exceptions

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


JObject.Parse(string, string, ParseOptions) Method

Parse the JSON string presuming it will return an JObject

public static QuickJSON.JObject 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

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

Exceptions

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


JObject.ParseThrowCommaEOL(string) Method

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

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

text System.String
Text to parse

Returns

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

Exceptions

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


JObject.PropertyNames() Method

Get an array of all property names

public string[] PropertyNames();
Returns

System.String[]


JObject.Remove(string) Method

Remove a JToken with this property name. True if found, false if not

public bool Remove(string key);
Parameters

key System.String

Returns

System.Boolean


JObject.Remove(string[]) Method

Remove JTokens with these property names.

public void Remove(params string[] key);
Parameters

key System.String[]


JObject.RemoveWildcard(string, bool) Method

Remove JTokens with these property names.

public void RemoveWildcard(string wildcard, bool caseinsensitive=false);
Parameters

wildcard System.String
Property name to find. May contain * and ? wildcards

caseinsensitive System.Boolean
True if case insensitive match


JObject.Rename(string, string) Method

Rename a field to newname. Returns true if done. If newname already exists it is overwritten.

public bool Rename(string fromname, string newname);
Parameters

fromname System.String
Name to rename

newname System.String
New name

Returns

System.Boolean
true if fromname exists.


JObject.TryGetValue(string, JToken) Method

Get a JToken by this property name

public bool TryGetValue(string name, out QuickJSON.JToken token);
Parameters

name System.String
Name of property

token JToken
Where to store the found JToken

Returns

System.Boolean
If property is not found, return false (null in token), else return true (token has found item)


JObject.UnknownProperties(string[]) Method

Return other property names not in this list

public System.Collections.Generic.IEnumerable<string> UnknownProperties(params string[] name);
Parameters

name System.String[]

Returns

System.Collections.Generic.IEnumerable<System.String>


JObject.UnknownProperties(string[], string[]) Method

Return other property names not in this pair of lists

public System.Collections.Generic.IEnumerable<string> UnknownProperties(string[] name, params string[] name2);
Parameters

name System.String[]

name2 System.String[]

Returns

System.Collections.Generic.IEnumerable<System.String>

Clone this wiki locally