Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class Newtonsoft.​Json.​Linq.​JToken
Assembly: Newtonsoft.Json
Inheritance: object → JToken
Implemented Interfaces
- IJEnumerable`1 (Inherits: System.​Collections.​Generic.​IEnumerable<​JToken>System.​Collections.​IEnumerable)
- IJsonLineInfo
- System.​Dynamic.​IDynamicMetaObjectProvider
Represents an abstract JSON token.
Properties
public static
JTokenEqualityComparer
EqualityComparer
Gets a comparer that can compare two tokens for value equality.
public
JContainer
Parent
Gets or sets the parent.
public
JToken
Root
Gets the root <see cref="T:Newtonsoft.Json.Linq.JToken" /> of this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
JTokenType
Type
Gets the node type for this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
bool
HasValues
Gets a value indicating whether this token has child tokens.
public
JToken
Next
Gets the next sibling token of this node.
public
JToken
Previous
Gets the previous sibling token of this node.
public
string
Path
Gets the path of the JSON token.
public
JToken
Item
public
JToken
First
Get the first child token of this token.
public
JToken
Last
Get the last child token of this token.
Methods
WriteToAsync​(JsonWriter writer,
System.​Threading.​CancellationToken cancellationToken,
JsonConverter[] converters)
Writes this token to a <see cref="T:Newtonsoft.Json.JsonWriter" /> asynchronously.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous write operation.
writer
A <see cref="T:Newtonsoft.Json.JsonWriter" /> into which this method will write.
cancellationToken
The token to monitor for cancellation requests.
converters
A collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> which will be used when writing the token.
WriteToAsync​(JsonWriter writer,
JsonConverter[] converters)
Writes this token to a <see cref="T:Newtonsoft.Json.JsonWriter" /> asynchronously.
Returns A <see cref="T:System.Threading.Tasks.Task" /> that represents the asynchronous write operation.
writer
A <see cref="T:Newtonsoft.Json.JsonWriter" /> into which this method will write.
converters
A collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> which will be used when writing the token.
public static
System.​Threading.​Tasks.​Task<​JToken>
ReadFromAsync​(JsonReader reader,
System.​Threading.​CancellationToken cancellationToken = null)
Asynchronously creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:System.Threading.Tasks.Task`1" /> that represents the asynchronous creation. The
<see cref="P:System.Threading.Tasks.Task`1.Result" /> property returns a <see cref="T:Newtonsoft.Json.Linq.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.
reader
An <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
System.​Threading.​Tasks.​Task<​JToken>
ReadFromAsync​(JsonReader reader,
JsonLoadSettings settings,
System.​Threading.​CancellationToken cancellationToken = null)
Asynchronously creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:System.Threading.Tasks.Task`1" /> that represents the asynchronous creation. The
<see cref="P:System.Threading.Tasks.Task`1.Result" /> property returns a <see cref="T:Newtonsoft.Json.Linq.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.
reader
An <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
settings
The <see cref="T:Newtonsoft.Json.Linq.JsonLoadSettings" /> used to load the JSON.
If this is <c>null</c> , default load settings will be used.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
System.​Threading.​Tasks.​Task<​JToken>
LoadAsync​(JsonReader reader,
System.​Threading.​CancellationToken cancellationToken = null)
Asynchronously creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:System.Threading.Tasks.Task`1" /> that represents the asynchronous creation. The <see cref="P:System.Threading.Tasks.Task`1.Result" />
property returns a <see cref="T:Newtonsoft.Json.Linq.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.
reader
A <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
System.​Threading.​Tasks.​Task<​JToken>
LoadAsync​(JsonReader reader,
JsonLoadSettings settings,
System.​Threading.​CancellationToken cancellationToken = null)
Asynchronously creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:System.Threading.Tasks.Task`1" /> that represents the asynchronous creation. The <see cref="P:System.Threading.Tasks.Task`1.Result" />
property returns a <see cref="T:Newtonsoft.Json.Linq.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.
reader
A <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
settings
The <see cref="T:Newtonsoft.Json.Linq.JsonLoadSettings" /> used to load the JSON.
If this is <c>null</c> , default load settings will be used.
cancellationToken
The token to monitor for cancellation requests. The default value is <see cref="P:System.Threading.CancellationToken.None" /> .
public static
bool
DeepEquals​(JToken t1,
JToken t2)
Compares the values of two tokens, including the values of all descendant tokens.
Returns <c>true</c> if the tokens are equal; otherwise <c>false</c> .
t1
The first <see cref="T:Newtonsoft.Json.Linq.JToken" /> to compare.
t2
The second <see cref="T:Newtonsoft.Json.Linq.JToken" /> to compare.
public
void
AddAfterSelf​(object content)
Adds the specified content immediately after this token.
content
A content object that contains simple content or a collection of content objects to be added after this token.
public
void
AddBeforeSelf​(object content)
Adds the specified content immediately before this token.
content
A content object that contains simple content or a collection of content objects to be added before this token.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
Ancestors​()
Returns a collection of the ancestor tokens of this token.
Returns A collection of the ancestor tokens of this token.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
AncestorsAndSelf​()
Returns a collection of tokens that contain this token, and the ancestors of this token.
Returns A collection of tokens that contain this token, and the ancestors of this token.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
AfterSelf​()
Returns a collection of the sibling tokens after this token, in document order.
Returns A collection of the sibling tokens after this tokens, in document order.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
BeforeSelf​()
Returns a collection of the sibling tokens before this token, in document order.
Returns A collection of the sibling tokens before this token, in document order.
public
T
Value​(object key)
Gets the <see cref="T:Newtonsoft.Json.Linq.JToken" /> with the specified key converted to the specified type.
Returns The converted token value.
key
The token key.
public
JEnumerable<​JToken>
Children​()
Returns a collection of the child tokens of this token, in document order.
Returns An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:Newtonsoft.Json.Linq.JToken" /> containing the child tokens of this <see cref="T:Newtonsoft.Json.Linq.JToken" /> , in document order.
public
JEnumerable<​T>
Children​()
Returns a collection of the child tokens of this token, in document order, filtered by the specified type.
Returns A <see cref="T:Newtonsoft.Json.Linq.JEnumerable`1" /> containing the child tokens of this <see cref="T:Newtonsoft.Json.Linq.JToken" /> , in document order.
public
System.​Collections.​Generic.​IEnumerable<​T>
Values​()
Returns a collection of the child values of this token, in document order.
Returns A <see cref="T:System.Collections.Generic.IEnumerable`1" /> containing the child values of this <see cref="T:Newtonsoft.Json.Linq.JToken" /> , in document order.
public
void
Remove​()
Removes this token from its parent.
value
The value.
public
void
WriteTo​(JsonWriter writer,
JsonConverter[] converters)
Writes this token to a <see cref="T:Newtonsoft.Json.JsonWriter" /> .
writer
A <see cref="T:Newtonsoft.Json.JsonWriter" /> into which this method will write.
converters
A collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> which will be used when writing the token.
public
string
ToString​()
Returns the indented JSON for this token.
Returns The indented JSON for this token.
public
string
ToString​(Formatting formatting,
JsonConverter[] converters)
Returns the JSON for this token using the given formatting and converters.
Returns The JSON for this token using the given formatting and converters.
formatting
Indicates how the output should be formatted.
converters
A collection of <see cref="T:Newtonsoft.Json.JsonConverter" /> s which will be used when writing the token.
public
JsonReader
CreateReader​()
Creates a <see cref="T:Newtonsoft.Json.JsonReader" /> for this token.
Returns A <see cref="T:Newtonsoft.Json.JsonReader" /> that can be used to read this token and its descendants.
public static
JToken
FromObject​(object o)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from an object.
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> with the value of the specified object.
o
The object that will be used to create <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public static
JToken
FromObject​(object o,
JsonSerializer jsonSerializer)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from an object using the specified <see cref="T:Newtonsoft.Json.JsonSerializer" /> .
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> with the value of the specified object.
o
The object that will be used to create <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
jsonSerializer
The <see cref="T:Newtonsoft.Json.JsonSerializer" /> that will be used when reading the object.
public
T
ToObject​()
Creates an instance of the specified .NET type from the <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns The new object created from the JSON value.
public
object
ToObject​(System.​Type objectType)
Creates an instance of the specified .NET type from the <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns The new object created from the JSON value.
objectType
The object type that the token will be deserialized to.
public
T
ToObject​(JsonSerializer jsonSerializer)
Creates an instance of the specified .NET type from the <see cref="T:Newtonsoft.Json.Linq.JToken" /> using the specified <see cref="T:Newtonsoft.Json.JsonSerializer" /> .
Returns The new object created from the JSON value.
jsonSerializer
The <see cref="T:Newtonsoft.Json.JsonSerializer" /> that will be used when creating the object.
public
object
ToObject​(System.​Type objectType,
JsonSerializer jsonSerializer)
Creates an instance of the specified .NET type from the <see cref="T:Newtonsoft.Json.Linq.JToken" /> using the specified <see cref="T:Newtonsoft.Json.JsonSerializer" /> .
Returns The new object created from the JSON value.
objectType
The object type that the token will be deserialized to.
jsonSerializer
The <see cref="T:Newtonsoft.Json.JsonSerializer" /> that will be used when creating the object.
public static
JToken
ReadFrom​(JsonReader reader)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:Newtonsoft.Json.Linq.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.
reader
A <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public static
JToken
ReadFrom​(JsonReader reader,
JsonLoadSettings settings)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:Newtonsoft.Json.Linq.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.
reader
An <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
settings
The <see cref="T:Newtonsoft.Json.Linq.JsonLoadSettings" /> used to load the JSON.
If this is <c>null</c> , default load settings will be used.
public static
JToken
Parse​(string json)
Load a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a string that contains JSON.
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> populated from the string that contains JSON.
json
A <see cref="T:System.String" /> that contains JSON.
public static
JToken
Parse​(string json,
JsonLoadSettings settings)
Load a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a string that contains JSON.
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> populated from the string that contains JSON.
json
A <see cref="T:System.String" /> that contains JSON.
settings
The <see cref="T:Newtonsoft.Json.Linq.JsonLoadSettings" /> used to load the JSON.
If this is <c>null</c> , default load settings will be used.
public static
JToken
Load​(JsonReader reader,
JsonLoadSettings settings)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:Newtonsoft.Json.Linq.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.
reader
A <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
settings
The <see cref="T:Newtonsoft.Json.Linq.JsonLoadSettings" /> used to load the JSON.
If this is <c>null</c> , default load settings will be used.
public static
JToken
Load​(JsonReader reader)
Creates a <see cref="T:Newtonsoft.Json.Linq.JToken" /> from a <see cref="T:Newtonsoft.Json.JsonReader" /> .
Returns A <see cref="T:Newtonsoft.Json.Linq.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.
reader
A <see cref="T:Newtonsoft.Json.JsonReader" /> positioned at the token to read into this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
JToken
SelectToken​(string path)
Selects a <see cref="T:Newtonsoft.Json.Linq.JToken" /> using a JPath expression. Selects the token that matches the object path.
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> , or <c>null</c> .
path
A <see cref="T:System.String" /> that contains a JPath expression.
public
JToken
SelectToken​(string path,
bool errorWhenNoMatch)
Selects a <see cref="T:Newtonsoft.Json.Linq.JToken" /> using a JPath expression. Selects the token that matches the object path.
Returns A <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
path
A <see cref="T:System.String" /> that contains a JPath expression.
errorWhenNoMatch
A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
SelectTokens​(string path)
Selects a collection of elements using a JPath expression.
Returns An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:Newtonsoft.Json.Linq.JToken" /> that contains the selected elements.
path
A <see cref="T:System.String" /> that contains a JPath expression.
public
System.​Collections.​Generic.​IEnumerable<​JToken>
SelectTokens​(string path,
bool errorWhenNoMatch)
Selects a collection of elements using a JPath expression.
Returns An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:Newtonsoft.Json.Linq.JToken" /> that contains the selected elements.
path
A <see cref="T:System.String" /> that contains a JPath expression.
errorWhenNoMatch
A flag to indicate whether an error should be thrown if no tokens are found when evaluating part of the expression.
GetMetaObject​(System.​Linq.​Expressions.​Expression parameter)
Returns the <see cref="T:System.Dynamic.DynamicMetaObject" /> responsible for binding operations performed on this object.
Returns The <see cref="T:System.Dynamic.DynamicMetaObject" /> to bind this object.
parameter
The expression tree representation of the runtime value.
public
JToken
DeepClone​()
Creates a new instance of the <see cref="T:Newtonsoft.Json.Linq.JToken" /> . All child tokens are recursively cloned.
Returns A new instance of the <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
void
AddAnnotation​(object annotation)
Adds an object to the annotation list of this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
annotation
The annotation to add.
public
T
Annotation​()
Get the first annotation object of the specified type from this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns The first annotation object that matches the specified type, or <c>null</c> if no annotation is of the specified type.
public
object
Annotation​(System.​Type type)
Gets the first annotation object of the specified type from this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns The first annotation object that matches the specified type, or <c>null</c> if no annotation is of the specified type.
type
The <see cref="P:Newtonsoft.Json.Linq.JToken.Type" /> of the annotation to retrieve.
public
System.​Collections.​Generic.​IEnumerable<​T>
Annotations​()
Gets a collection of annotations of the specified type for this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns An <see cref="T:System.Collections.Generic.IEnumerable`1" /> that contains the annotations for this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
System.​Collections.​Generic.​IEnumerable<​object>
Annotations​(System.​Type type)
Gets a collection of annotations of the specified type for this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
Returns An <see cref="T:System.Collections.Generic.IEnumerable`1" /> of <see cref="T:System.Object" /> that contains the annotations that match the specified type for this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
type
The <see cref="P:Newtonsoft.Json.Linq.JToken.Type" /> of the annotations to retrieve.
public
void
RemoveAnnotations​()
Removes the annotations of the specified type from this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
public
void
RemoveAnnotations​(System.​Type type)
Removes the annotations of the specified type from this <see cref="T:Newtonsoft.Json.Linq.JToken" /> .
type
The <see cref="P:Newtonsoft.Json.Linq.JToken.Type" /> of annotations to remove.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object