Class JToken
- Namespace
- Newtonsoft.Json.Linq
- Assembly
- Newtonsoft.Json.dll
Represents an abstract JSON token.
public abstract class JToken : IJEnumerable<JToken>, IEnumerable<JToken>, IEnumerable, IJsonLineInfo, ICloneable
- Inheritance
-
JToken
- Implements
- Derived
- Inherited Members
- Extension Methods
Properties
EqualityComparer
Gets a comparer that can compare two tokens for value equality.
public static JTokenEqualityComparer EqualityComparer { get; }
Property Value
- JTokenEqualityComparer
A JTokenEqualityComparer that can compare two nodes for value equality.
First
Get the first child token of this token.
public virtual JToken First { get; }
Property Value
HasValues
Gets a value indicating whether this token has childen tokens.
public abstract bool HasValues { get; }
Property Value
- bool
true
if this token has child values; otherwise,false
.
this[object]
Gets the JToken with the specified key.
public virtual JToken this[object key] { get; set; }
Parameters
key
object
Property Value
Last
Get the last child token of this token.
public virtual JToken Last { get; }
Property Value
Next
Gets the next sibling token of this node.
public JToken Next { get; }
Property Value
Parent
Gets or sets the parent.
public JContainer Parent { get; }
Property Value
- JContainer
The parent.
Previous
Gets the previous sibling token of this node.
public JToken Previous { get; }
Property Value
Root
public JToken Root { get; }
Property Value
Type
Gets the node type for this JToken.
public abstract JTokenType Type { get; }
Property Value
- JTokenType
The type.
Methods
AddAfterSelf(object)
Adds the specified content immediately after this token.
public void AddAfterSelf(object content)
Parameters
content
objectA content object that contains simple content or a collection of content objects to be added after this token.
AddBeforeSelf(object)
Adds the specified content immediately before this token.
public void AddBeforeSelf(object content)
Parameters
content
objectA content object that contains simple content or a collection of content objects to be added before this token.
AfterSelf()
Returns a collection of the sibling tokens after this token, in document order.
public IEnumerable<JToken> AfterSelf()
Returns
- IEnumerable<JToken>
A collection of the sibling tokens after this tokens, in document order.
Ancestors()
Returns a collection of the ancestor tokens of this token.
public IEnumerable<JToken> Ancestors()
Returns
- IEnumerable<JToken>
A collection of the ancestor tokens of this token.
BeforeSelf()
Returns a collection of the sibling tokens before this token, in document order.
public IEnumerable<JToken> BeforeSelf()
Returns
- IEnumerable<JToken>
A collection of the sibling tokens before this token, in document order.
Children()
Returns a collection of the child tokens of this token, in document order.
public virtual JEnumerable<JToken> Children()
Returns
- JEnumerable<JToken>
An IEnumerable<T> of JToken containing the child tokens of this JToken, in document order.
Children<T>()
Returns a collection of the child tokens of this token, in document order, filtered by the specified type.
public JEnumerable<T> Children<T>() where T : JToken
Returns
- JEnumerable<T>
A JEnumerable<T> containing the child tokens of this JToken, in document order.
Type Parameters
T
The type to filter the child tokens on.
CreateReader()
Creates an JsonReader for this token.
public JsonReader CreateReader()
Returns
- JsonReader
An JsonReader that can be used to read this token and its descendants.
DeepClone()
Creates a new instance of the JToken. All child tokens are recursively cloned.
public JToken DeepClone()
Returns
DeepEquals(JToken, JToken)
Compares the values of two tokens, including the values of all descendant tokens.
public static bool DeepEquals(JToken t1, JToken t2)
Parameters
Returns
- bool
true if the tokens are equal; otherwise false.
FromObject(object)
Creates a JToken from an object.
public static JToken FromObject(object o)
Parameters
Returns
FromObject(object, JsonSerializer)
Creates a JToken from an object using the specified JsonSerializer.
public static JToken FromObject(object o, JsonSerializer jsonSerializer)
Parameters
o
objectThe object that will be used to create JToken.
jsonSerializer
JsonSerializerThe JsonSerializer that will be used when reading the object.
Returns
Load(JsonReader)
Creates a JToken from a JsonReader.
public static JToken Load(JsonReader reader)
Parameters
reader
JsonReaderAn 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(string)
Load a JToken from a string that contains JSON.
public static JToken Parse(string json)
Parameters
Returns
ReadFrom(JsonReader)
Creates a JToken from a JsonReader.
public static JToken ReadFrom(JsonReader reader)
Parameters
reader
JsonReaderAn 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()
Removes this token from its parent.
public void Remove()
Replace(JToken)
Replaces this token with the specified token.
public void Replace(JToken value)
Parameters
value
JTokenThe value.
SelectToken(string)
Selects the token that matches the object path.
public JToken SelectToken(string path)
Parameters
path
stringThe object path from the current JToken to the JToken to be returned. This must be a string of property names or array indexes separated by periods, such as
in C# orTables[0].DefaultView[0].Price
in Visual Basic.Tables(0).DefaultView(0).Price
Returns
SelectToken(string, bool)
Selects the token that matches the object path.
public JToken SelectToken(string path, bool errorWhenNoMatch)
Parameters
path
stringThe object path from the current JToken to the JToken to be returned. This must be a string of property names or array indexes separated by periods, such as
in C# orTables[0].DefaultView[0].Price
in Visual Basic.Tables(0).DefaultView(0).Price
errorWhenNoMatch
boolA flag to indicate whether an error should be thrown if no token is found.
Returns
ToObject<T>()
Creates the specified .NET type from the JToken.
public T ToObject<T>()
Returns
- T
The new object created from the JSON value.
Type Parameters
T
ToObject<T>(JsonSerializer)
Creates the specified .NET type from the JToken using the specified JsonSerializer.
public T ToObject<T>(JsonSerializer jsonSerializer)
Parameters
jsonSerializer
JsonSerializerThe JsonSerializer that will be used when creating the object.
Returns
- T
The new object created from the JSON value.
Type Parameters
T
ToString()
Returns the indented JSON for this token.
public override string ToString()
Returns
- string
The indented JSON for this token.
ToString(Formatting, params JsonConverter[])
Returns the JSON for this token using the given formatting and converters.
public string ToString(Formatting formatting, params JsonConverter[] converters)
Parameters
formatting
FormattingIndicates how the output is formatted.
converters
JsonConverter[]A collection of JsonConverter which will be used when writing the token.
Returns
- string
The JSON for this token using the given formatting and converters.
Value<T>(object)
Gets the JToken with the specified key converted to the specified type.
public virtual T Value<T>(object key)
Parameters
key
objectThe token key.
Returns
- T
The converted token value.
Type Parameters
T
The type to convert the token to.
Values<T>()
Returns a collection of the child values of this token, in document order.
public virtual IEnumerable<T> Values<T>()
Returns
- IEnumerable<T>
A IEnumerable<T> containing the child values of this JToken, in document order.
Type Parameters
T
The type to convert the values to.
WriteTo(JsonWriter, params JsonConverter[])
Writes this token to a JsonWriter.
public abstract void WriteTo(JsonWriter writer, params JsonConverter[] converters)
Parameters
writer
JsonWriterA JsonWriter into which this method will write.
converters
JsonConverter[]A collection of JsonConverter which will be used when writing the token.
Operators
explicit operator bool(JToken)
public static explicit operator bool(JToken value)
Parameters
value
JTokenThe value.
Returns
- bool
The result of the conversion.
explicit operator byte[](JToken)
public static explicit operator byte[](JToken value)
Parameters
value
JTokenThe value.
Returns
- byte[]
The result of the conversion.
explicit operator DateTime(JToken)
public static explicit operator DateTime(JToken value)
Parameters
value
JTokenThe value.
Returns
- DateTime
The result of the conversion.
explicit operator DateTimeOffset(JToken)
Performs an explicit conversion from JToken to DateTimeOffset.
public static explicit operator DateTimeOffset(JToken value)
Parameters
value
JTokenThe value.
Returns
- DateTimeOffset
The result of the conversion.
explicit operator decimal(JToken)
public static explicit operator decimal(JToken value)
Parameters
value
JTokenThe value.
Returns
- decimal
The result of the conversion.
explicit operator double(JToken)
public static explicit operator double(JToken value)
Parameters
value
JTokenThe value.
Returns
- double
The result of the conversion.
explicit operator short(JToken)
public static explicit operator short(JToken value)
Parameters
value
JTokenThe value.
Returns
- short
The result of the conversion.
explicit operator int(JToken)
public static explicit operator int(JToken value)
Parameters
value
JTokenThe value.
Returns
- int
The result of the conversion.
explicit operator long(JToken)
public static explicit operator long(JToken value)
Parameters
value
JTokenThe value.
Returns
- long
The result of the conversion.
explicit operator bool?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator bool?(JToken value)
Parameters
value
JTokenThe value.
Returns
- bool?
The result of the conversion.
explicit operator DateTimeOffset?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator DateTimeOffset?(JToken value)
Parameters
value
JTokenThe value.
Returns
- DateTimeOffset?
The result of the conversion.
explicit operator DateTime?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator DateTime?(JToken value)
Parameters
value
JTokenThe value.
Returns
- DateTime?
The result of the conversion.
explicit operator decimal?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator decimal?(JToken value)
Parameters
value
JTokenThe value.
Returns
- decimal?
The result of the conversion.
explicit operator double?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator double?(JToken value)
Parameters
value
JTokenThe value.
Returns
- double?
The result of the conversion.
explicit operator short?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator short?(JToken value)
Parameters
value
JTokenThe value.
Returns
- short?
The result of the conversion.
explicit operator int?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator int?(JToken value)
Parameters
value
JTokenThe value.
Returns
- int?
The result of the conversion.
explicit operator long?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator long?(JToken value)
Parameters
value
JTokenThe value.
Returns
- long?
The result of the conversion.
explicit operator float?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
public static explicit operator float?(JToken value)
Parameters
value
JTokenThe value.
Returns
- float?
The result of the conversion.
explicit operator ushort?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
[CLSCompliant(false)]
public static explicit operator ushort?(JToken value)
Parameters
value
JTokenThe value.
Returns
- ushort?
The result of the conversion.
explicit operator uint?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
[CLSCompliant(false)]
public static explicit operator uint?(JToken value)
Parameters
value
JTokenThe value.
Returns
- uint?
The result of the conversion.
explicit operator ulong?(JToken)
Performs an explicit conversion from JToken to Nullable<T>.
[CLSCompliant(false)]
public static explicit operator ulong?(JToken value)
Parameters
value
JTokenThe value.
Returns
- ulong?
The result of the conversion.
explicit operator float(JToken)
public static explicit operator float(JToken value)
Parameters
value
JTokenThe value.
Returns
- float
The result of the conversion.
explicit operator string(JToken)
public static explicit operator string(JToken value)
Parameters
value
JTokenThe value.
Returns
- string
The result of the conversion.
explicit operator ushort(JToken)
[CLSCompliant(false)]
public static explicit operator ushort(JToken value)
Parameters
value
JTokenThe value.
Returns
- ushort
The result of the conversion.
explicit operator uint(JToken)
[CLSCompliant(false)]
public static explicit operator uint(JToken value)
Parameters
value
JTokenThe value.
Returns
- uint
The result of the conversion.
explicit operator ulong(JToken)
[CLSCompliant(false)]
public static explicit operator ulong(JToken value)
Parameters
value
JTokenThe value.
Returns
- ulong
The result of the conversion.
implicit operator JToken(bool)
public static implicit operator JToken(bool value)
Parameters
Returns
implicit operator JToken(byte[])
public static implicit operator JToken(byte[] value)
Parameters
Returns
implicit operator JToken(DateTime)
public static implicit operator JToken(DateTime value)
Parameters
Returns
implicit operator JToken(DateTimeOffset)
Performs an implicit conversion from DateTimeOffset to JToken.
public static implicit operator JToken(DateTimeOffset value)
Parameters
value
DateTimeOffsetThe value to create a JValue from.
Returns
implicit operator JToken(decimal)
public static implicit operator JToken(decimal value)
Parameters
Returns
implicit operator JToken(double)
public static implicit operator JToken(double value)
Parameters
Returns
implicit operator JToken(short)
[CLSCompliant(false)]
public static implicit operator JToken(short value)
Parameters
Returns
implicit operator JToken(int)
public static implicit operator JToken(int value)
Parameters
Returns
implicit operator JToken(long)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(long value)
Parameters
Returns
implicit operator JToken(bool?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(bool? value)
Parameters
Returns
implicit operator JToken(DateTimeOffset?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(DateTimeOffset? value)
Parameters
value
DateTimeOffset?The value to create a JValue from.
Returns
implicit operator JToken(DateTime?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(DateTime? value)
Parameters
Returns
implicit operator JToken(decimal?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(decimal? value)
Parameters
Returns
implicit operator JToken(double?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(double? value)
Parameters
Returns
implicit operator JToken(short?)
Performs an implicit conversion from Nullable<T> to JToken.
[CLSCompliant(false)]
public static implicit operator JToken(short? value)
Parameters
Returns
implicit operator JToken(int?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(int? value)
Parameters
Returns
implicit operator JToken(long?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(long? value)
Parameters
Returns
implicit operator JToken(float?)
Performs an implicit conversion from Nullable<T> to JToken.
public static implicit operator JToken(float? value)
Parameters
Returns
implicit operator JToken(ushort?)
Performs an implicit conversion from Nullable<T> to JToken.
[CLSCompliant(false)]
public static implicit operator JToken(ushort? value)
Parameters
Returns
implicit operator JToken(uint?)
Performs an implicit conversion from Nullable<T> to JToken.
[CLSCompliant(false)]
public static implicit operator JToken(uint? value)
Parameters
Returns
implicit operator JToken(ulong?)
Performs an implicit conversion from Nullable<T> to JToken.
[CLSCompliant(false)]
public static implicit operator JToken(ulong? value)
Parameters
Returns
implicit operator JToken(float)
public static implicit operator JToken(float value)
Parameters
Returns
implicit operator JToken(string)
public static implicit operator JToken(string value)
Parameters
Returns
implicit operator JToken(ushort)
[CLSCompliant(false)]
public static implicit operator JToken(ushort value)
Parameters
Returns
implicit operator JToken(uint)
[CLSCompliant(false)]
public static implicit operator JToken(uint value)
Parameters
Returns
implicit operator JToken(ulong)
[CLSCompliant(false)]
public static implicit operator JToken(ulong value)