JToken Class
Namespace: Stimulsoft.Base.Json.Linq
Represents an abstract JSON token.
Inheritance
Implements: IJEnumerable<JToken>, IJsonLineInfo
Properties
| Property | Type | Description |
|---|---|---|
| HasValues | bool | Gets a value indicating whether this token has child tokens. |
| Type | JTokenType | Gets the node type for this JToken. |
Methods
| Method | Returns | Description |
|---|---|---|
| AddAfterSelf | void | Adds the specified content immediately after this token. |
| AddAnnotation | void | Adds an object to the annotation list of this JToken. |
| AddBeforeSelf | void | Adds the specified content immediately before this token. |
| AfterSelf | IEnumerable<JToken> | Returns a collection of the sibling tokens after this token, in document order. |
| Ancestors | IEnumerable<JToken> | Returns a collection of the ancestor tokens of this token. |
| AncestorsAndSelf | IEnumerable<JToken> | Returns a collection of tokens that contain this token, and the ancestors of this token. |
| Annotation | object | Gets the first annotation object of the specified type from this JToken. |
| Annotations | IEnumerable | Gets a collection of annotations of the specified type for this JToken. |
| BeforeSelf | IEnumerable<JToken> | Returns a collection of the sibling tokens before this token, in document order. |
| Children (+1 overloads) | JEnumerable<JToken> | Returns a collection of the child tokens of this token, in document order. |
| CreateReader | JsonReader | Creates an JsonReader for this token. |
| DeepClone | JToken | Creates a new instance of the JToken. All child tokens are recursively cloned. |
DeepEquals static |
bool | Compares the values of two tokens, including the values of all descendant tokens. |
FromObject static (+1 overloads) |
JToken | Creates a JToken from an object. |
| GetMetaObject | DynamicMetaObject | Returns the DynamicMetaObject responsible for binding operations performed on this object. |
Load static |
JToken | Creates a JToken from a JsonReader. |
Parse static |
JToken | Load a JToken from a string that contains JSON. |
ReadFrom static |
JToken | Creates a JToken from a JsonReader. |
| Remove | void | Removes this token from its parent. |
| RemoveAnnotations | void | Removes the annotations of the specified type from this JToken. |
| Replace | void | Replaces this token with the specified token. |
| SelectToken (+1 overloads) | JToken | Selects a JToken using a JPath expression. Selects the token that matches the object path. |
| SelectTokens (+1 overloads) | IEnumerable<JToken> | Selects a collection of elements using a JPath expression. |
| ToObject (+3 overloads) | T | Creates the specified .NET type from the JToken. |
| ToString (+2 overloads) | string | Returns the indented JSON for this token. |
| Value | T | Gets the JToken with the specified key converted to the specified type. |
| Values | IEnumerable |
Returns a collection of the child values of this token, in document order. |
| WriteTo | void | Writes this token to a JsonWriter. |
Method Details
AddAfterSelf
AddAfterSelf(content: object): void
Adds the specified content immediately after this token.
Parameters
- content (object) — A content object that contains simple content or a collection of content objects to be added after this token.
AddAnnotation
AddAnnotation(annotation: object): void
Adds an object to the annotation list of this JToken.
Parameters
- annotation (object) — The annotation to add.
AddBeforeSelf
AddBeforeSelf(content: object): void
Adds the specified content immediately before this token.
Parameters
- content (object) — A content object that contains simple content or a collection of content objects to be added before this token.
AfterSelf
AfterSelf(): IEnumerable<JToken>
Returns a collection of the sibling tokens after this token, in document order.
Returns IEnumerable<JToken> — A collection of the sibling tokens after this tokens, in document order.
Ancestors
Ancestors(): IEnumerable<JToken>
Returns a collection of the ancestor tokens of this token.
Returns IEnumerable<JToken> — A collection of the ancestor tokens of this token.
AncestorsAndSelf
AncestorsAndSelf(): IEnumerable<JToken>
Returns a collection of tokens that contain this token, and the ancestors of this token.
Returns IEnumerable<JToken> — A collection of tokens that contain this token, and the ancestors of this token.
Annotation
Annotation(type: Type): object
Gets the first annotation object of the specified type from this JToken.
Parameters
- type (Type) — The Type of the annotation to retrieve.
Returns object — The first annotation object that matches the specified type, or null if no annotation is of the specified type.
Annotations
Annotations(type: Type): IEnumerable
Gets a collection of annotations of the specified type for this JToken.
Parameters
- type (Type) — The Type of the annotations to retrieve.
Returns IEnumerable
BeforeSelf
BeforeSelf(): IEnumerable<JToken>
Returns a collection of the sibling tokens before this token, in document order.
Returns IEnumerable<JToken> — A collection of the sibling tokens before this token, in document order.
Children
Children(): JEnumerable<JToken>
Returns a collection of the child tokens of this token, in document order.
Returns JEnumerable<JToken> — An IEnumerable{T} of JToken containing the child tokens of this JToken, in document order.
Children(): JEnumerable
Returns a collection of the child tokens of this token, in document order, filtered by the specified type.
Returns JEnumerable
CreateReader
CreateReader(): JsonReader
Creates an JsonReader for this token.
Returns JsonReader — An JsonReader that can be used to read this token and its descendants.
DeepClone
DeepClone(): JToken
Creates a new instance of the JToken. All child tokens are recursively cloned.
Returns JToken — A new instance of the JToken.
DeepEquals static
DeepEquals(t1: JToken, t2: JToken): bool
Compares the values of two tokens, including the values of all descendant tokens.
Parameters
Returns bool — true if the tokens are equal; otherwise false.
FromObject static
FromObject(o: object): JToken
Creates a JToken from an object.
Parameters
- o (object) — The object that will be used to create JToken.
Returns JToken — A JToken with the value of the specified object
FromObject(o: object, jsonSerializer: JsonSerializer): JToken
Creates a JToken from an object using the specified JsonSerializer.
Parameters
- o (object) — The object that will be used to create JToken.
- jsonSerializer (JsonSerializer) — The JsonSerializer that will be used when reading the object.
Returns JToken — A JToken with the value of the specified object
GetMetaObject
GetMetaObject(parameter: Expression): DynamicMetaObject
Returns the DynamicMetaObject responsible for binding operations performed on this object.
Parameters
- parameter (Expression) — The expression tree representation of the runtime value.
Returns DynamicMetaObject — The DynamicMetaObject to bind this object.
Load static
Load(reader: JsonReader): JToken
Creates a JToken from a JsonReader.
Parameters
- reader (JsonReader) — An JsonReader positioned at the token to read into this JToken.
Returns JToken — An JToken that contains the token and its descendant tokens that were read from the reader. The runtime type of the token is determined by the token type of the first token encountered in the reader.
Parse static
Parse(json: string): JToken
Load a JToken from a string that contains JSON.
Parameters
- json (string) — A String that contains JSON.
Returns JToken — A JToken populated from the string that contains JSON.
ReadFrom static
ReadFrom(reader: JsonReader): JToken
Creates a JToken from a JsonReader.
Parameters
- reader (JsonReader) — An JsonReader positioned at the token to read into this JToken.
Returns JToken — An JToken that contains the token and its descendant tokens that were read from the reader. The runtime type of the token is determined by the token type of the first token encountered in the reader.
Remove
Remove(): void
Removes this token from its parent.
RemoveAnnotations
RemoveAnnotations(type: Type): void
Removes the annotations of the specified type from this JToken.
Parameters
- type (Type) — The Type of annotations to remove.
Replace
Replace(value: JToken): void
Replaces this token with the specified token.
Parameters
- value (JToken) — The value.
SelectToken
SelectToken(path: string): JToken
Selects a JToken using a JPath expression. Selects the token that matches the object path.
Parameters
- path (string) — A String that contains a JPath expression.
Returns JToken — A JToken, or null.
SelectToken(path: string, errorWhenNoMatch: bool): JToken
Selects a JToken using a JPath expression. Selects the token that matches the object path.
Parameters
- path (string) — A String that contains a JPath expression.
- errorWhenNoMatch (bool) — A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression.
Returns JToken — A JToken.
SelectTokens
SelectTokens(path: string): IEnumerable<JToken>
Selects a collection of elements using a JPath expression.
Parameters
- path (string) — A String that contains a JPath expression.
Returns IEnumerable<JToken> — An IEnumerable{JToken} that contains the selected elements.
SelectTokens(path: string, errorWhenNoMatch: bool): IEnumerable<JToken>
Selects a collection of elements using a JPath expression.
Parameters
- path (string) — A String that contains a JPath expression.
- errorWhenNoMatch (bool) — A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression.
Returns IEnumerable<JToken> — An IEnumerable{JToken} that contains the selected elements.
ToObject
ToObject(): T
Creates the specified .NET type from the JToken.
Returns T — The new object created from the JSON value.
ToObject(objectType: Type): object
Creates the specified .NET type from the JToken.
Parameters
- objectType (Type) — The object type that the token will be deserialized to.
Returns object — The new object created from the JSON value.
ToObject(jsonSerializer: JsonSerializer): T
Creates the specified .NET type from the JToken using the specified JsonSerializer.
Parameters
- jsonSerializer (JsonSerializer) — The JsonSerializer that will be used when creating the object.
Returns T — The new object created from the JSON value.
ToObject(objectType: Type, jsonSerializer: JsonSerializer): object
Creates the specified .NET type from the JToken using the specified JsonSerializer.
Parameters
- objectType (Type) — The object type that the token will be deserialized to.
- jsonSerializer (JsonSerializer) — The JsonSerializer that will be used when creating the object.
Returns object — The new object created from the JSON value.
ToString
ToString(): string
Returns the indented JSON for this token.
Returns string — The indented JSON for this token.
ToString(cultureInfo: CultureInfo): string
Returns the indented JSON for this token.
Parameters
- cultureInfo (CultureInfo)
Returns string — The indented JSON for this token.
ToString(formatting: Formatting, cultureInfo: CultureInfo, **: JsonConverterconverters): string
Returns the JSON for this token using the given formatting and converters.
Parameters
- formatting (Formatting) — Indicates how the output is formatted.
- cultureInfo (CultureInfo)
- ** (JsonConverterconverters)
Returns string — The JSON for this token using the given formatting and converters.
Value
Value(key: object): T
Gets the JToken with the specified key converted to the specified type.
Parameters
- key (object) — The token key.
Returns T — The converted token value.
Values
Values(): IEnumerable
Returns a collection of the child values of this token, in document order.
Returns IEnumerable
WriteTo
WriteTo(writer: JsonWriter, **: JsonConverterconverters): void
Writes this token to a JsonWriter.
Parameters
- writer (JsonWriter) — A JsonWriter into which this method will write.
- ** (JsonConverterconverters)