Class JObject
Represents a JSON object.
Implements
Inherited Members
Namespace: Bayat.Json.Linq
Assembly: Bayat.Json.Runtime.dll
Syntax
public class JObject : JContainer, IJEnumerable<JToken>, IJsonLineInfo, ICloneable, IDynamicMetaObjectProvider, IList<JToken>, ICollection<JToken>, IEnumerable<JToken>, ITypedList, IBindingList, IList, ICollection, INotifyCollectionChanged, IDictionary<string, JToken>, ICollection<KeyValuePair<string, JToken>>, IEnumerable<KeyValuePair<string, JToken>>, IEnumerable, INotifyPropertyChanged, ICustomTypeDescriptor, INotifyPropertyChanging
Examples
Constructors
| Improve this Doc View SourceJObject()
Initializes a new instance of the JObject class.
Declaration
public JObject()
JObject(JObject)
Declaration
public JObject(JObject other)
Parameters
Type | Name | Description |
---|---|---|
JObject | other | A JObject object to copy from. |
JObject(Object)
Initializes a new instance of the JObject class with the specified content.
Declaration
public JObject(object content)
Parameters
Type | Name | Description |
---|---|---|
System.Object | content | The contents of the object. |
JObject(Object[])
Initializes a new instance of the JObject class with the specified content.
Declaration
public JObject(params object[] content)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | content | The contents of the object. |
Properties
| Improve this Doc View SourceChildrenTokens
Gets the container's children tokens.
Declaration
protected override IList<JToken> ChildrenTokens { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<JToken> | The container's children tokens. |
Overrides
| Improve this Doc View SourceItem[Object]
Gets the JToken with the specified key.
Declaration
public override JToken this[object key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Object | key |
Property Value
Type | Description |
---|---|
JToken | The JToken with the specified key. |
Overrides
| Improve this Doc View SourceItem[String]
Gets or sets the JToken with the specified property name.
Declaration
public JToken this[string propertyName] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName |
Property Value
Type | Description |
---|---|
JToken |
Type
Gets the node type for this JToken.
Declaration
public override JTokenType Type { get; }
Property Value
Type | Description |
---|---|
JTokenType | The type. |
Overrides
Methods
| Improve this Doc View SourceAdd(String, JToken)
Adds the specified property name.
Declaration
public void Add(string propertyName, JToken value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
JToken | value | The value. |
CloneToken()
Declaration
public override JToken CloneToken()
Returns
Type | Description |
---|---|
JToken |
Overrides
| Improve this Doc View SourceDeepEquals(JToken)
Declaration
public override bool DeepEquals(JToken node)
Parameters
Type | Name | Description |
---|---|---|
JToken | node |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
| Improve this Doc View SourceFromObject(Object)
Creates a JObject from an object.
Declaration
public static JObject FromObject(object o)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o | The object that will be used to create JObject. |
Returns
Type | Description |
---|---|
JObject | A JObject with the values of the specified object |
FromObject(Object, JsonSerializer)
Creates a JObject from an object.
Declaration
public static JObject FromObject(object o, JsonSerializer jsonSerializer)
Parameters
Type | Name | Description |
---|---|---|
System.Object | o | The object that will be used to create JObject. |
JsonSerializer | jsonSerializer | The JsonSerializer that will be used to read the object. |
Returns
Type | Description |
---|---|
JObject | A JObject with the values of the specified object |
GetDeepHashCode()
Declaration
public override int GetDeepHashCode()
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
| Improve this Doc View SourceGetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<KeyValuePair<string, JToken>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.String, JToken>> | A System.Collections.Generic.IEnumerator<T> that can be used to iterate through the collection. |
GetMetaObject(Expression)
Returns the System.Dynamic.DynamicMetaObject responsible for binding operations performed on this object.
Declaration
protected override DynamicMetaObject GetMetaObject(Expression parameter)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression | parameter | The expression tree representation of the runtime value. |
Returns
Type | Description |
---|---|
System.Dynamic.DynamicMetaObject | The System.Dynamic.DynamicMetaObject to bind this object. |
Overrides
| Improve this Doc View SourceGetValue(String)
Gets the JToken with the specified property name.
Declaration
public JToken GetValue(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
Returns
Type | Description |
---|---|
JToken | The JToken with the specified property name. |
GetValue(String, StringComparison)
Gets the JToken with the specified property name. The exact property name will be searched for first and if no matching property is found then the System.StringComparison will be used to match a property.
Declaration
public JToken GetValue(string propertyName, StringComparison comparison)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
System.StringComparison | comparison | One of the enumeration values that specifies how the strings will be compared. |
Returns
Type | Description |
---|---|
JToken | The JToken with the specified property name. |
IndexOfItem(JToken)
Declaration
public override int IndexOfItem(JToken item)
Parameters
Type | Name | Description |
---|---|---|
JToken | item |
Returns
Type | Description |
---|---|
System.Int32 |
Overrides
| Improve this Doc View SourceInsertItem(Int32, JToken, Boolean)
Declaration
public override void InsertItem(int index, JToken item, bool skipParentCheck)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
JToken | item | |
System.Boolean | skipParentCheck |
Overrides
| Improve this Doc View SourceLoad(JsonReader)
Loads an JObject from a JsonReader.
Declaration
public static JObject Load(JsonReader reader)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | A JsonReader that will be read for the content of the JObject. |
Returns
Type | Description |
---|---|
JObject | A JObject that contains the JSON that was read from the specified JsonReader. |
Load(JsonReader, JsonLoadSettings)
Loads an JObject from a JsonReader.
Declaration
public static JObject Load(JsonReader reader, JsonLoadSettings settings)
Parameters
Type | Name | Description |
---|---|---|
JsonReader | reader | A JsonReader that will be read for the content of the JObject. |
JsonLoadSettings | settings | The JsonLoadSettings used to load the JSON. If this is null, default load settings will be used. |
Returns
Type | Description |
---|---|
JObject | A JObject that contains the JSON that was read from the specified JsonReader. |
MergeItem(Object, JsonMergeSettings)
Declaration
public override void MergeItem(object content, JsonMergeSettings settings)
Parameters
Type | Name | Description |
---|---|---|
System.Object | content | |
JsonMergeSettings | settings |
Overrides
| Improve this Doc View SourceOnPropertyChanged(String)
Raises the PropertyChanged event with the provided arguments.
Declaration
protected virtual void OnPropertyChanged(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
OnPropertyChanging(String)
Raises the PropertyChanging event with the provided arguments.
Declaration
protected virtual void OnPropertyChanging(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
Parse(String)
Load a JObject from a string that contains JSON.
Declaration
public static JObject Parse(string json)
Parameters
Type | Name | Description |
---|---|---|
System.String | json | A System.String that contains JSON. |
Returns
Type | Description |
---|---|
JObject | A JObject populated from the string that contains JSON. |
Examples
|
Improve this Doc
View Source
Parse(String, JsonLoadSettings)
Load a JObject from a string that contains JSON.
Declaration
public static JObject Parse(string json, JsonLoadSettings settings)
Parameters
Type | Name | Description |
---|---|---|
System.String | json | A System.String that contains JSON. |
JsonLoadSettings | settings | The JsonLoadSettings used to load the JSON. If this is null, default load settings will be used. |
Returns
Type | Description |
---|---|
JObject | A JObject populated from the string that contains JSON. |
Examples
|
Improve this Doc
View Source
Properties()
Gets an System.Collections.Generic.IEnumerable<T> of this object's properties.
Declaration
public IEnumerable<JProperty> Properties()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<JProperty> | An System.Collections.Generic.IEnumerable<T> of this object's properties. |
Property(String)
Gets a JProperty the specified name.
Declaration
public JProperty Property(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The property name. |
Returns
Type | Description |
---|---|
JProperty | A JProperty with the specified name or null. |
PropertyValues()
Gets an JEnumerable<T> of this object's property values.
Declaration
public JEnumerable<JToken> PropertyValues()
Returns
Type | Description |
---|---|
JEnumerable<JToken> | An JEnumerable<T> of this object's property values. |
Remove(String)
Removes the property with the specified name.
Declaration
public bool Remove(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
Returns
Type | Description |
---|---|
System.Boolean | true if item was successfully removed; otherwise, false. |
TryGetValue(String, out JToken)
Tries the get value.
Declaration
public bool TryGetValue(string propertyName, out JToken value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
JToken | value | The value. |
Returns
Type | Description |
---|---|
System.Boolean | true if a value was successfully retrieved; otherwise, false. |
TryGetValue(String, StringComparison, out JToken)
Tries to get the JToken with the specified property name. The exact property name will be searched for first and if no matching property is found then the System.StringComparison will be used to match a property.
Declaration
public bool TryGetValue(string propertyName, StringComparison comparison, out JToken value)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property. |
System.StringComparison | comparison | One of the enumeration values that specifies how the strings will be compared. |
JToken | value | The value. |
Returns
Type | Description |
---|---|
System.Boolean | true if a value was successfully retrieved; otherwise, false. |
ValidateToken(JToken, JToken)
Declaration
public override void ValidateToken(JToken o, JToken existing)
Parameters
Type | Name | Description |
---|---|---|
JToken | o | |
JToken | existing |
Overrides
| Improve this Doc View SourceWriteTo(JsonWriter, JsonConverter[])
Writes this token to a JsonWriter.
Declaration
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
Parameters
Type | Name | Description |
---|---|---|
JsonWriter | writer | A JsonWriter into which this method will write. |
JsonConverter[] | converters | A collection of JsonConverter which will be used when writing the token. |
Overrides
Events
| Improve this Doc View SourcePropertyChanged
Occurs when a property value changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
System.ComponentModel.PropertyChangedEventHandler |
PropertyChanging
Occurs when a property value is changing.
Declaration
public event PropertyChangingEventHandler PropertyChanging
Event Type
Type | Description |
---|---|
System.ComponentModel.PropertyChangingEventHandler |
Explicit Interface Implementations
| Improve this Doc View SourceICollection<KeyValuePair<String, JToken>>.Add(KeyValuePair<String, JToken>)
Declaration
void ICollection<KeyValuePair<string, JToken>>.Add(KeyValuePair<string, JToken> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.String, JToken> | item |
ICollection<KeyValuePair<String, JToken>>.Clear()
Declaration
void ICollection<KeyValuePair<string, JToken>>.Clear()
ICollection<KeyValuePair<String, JToken>>.Contains(KeyValuePair<String, JToken>)
Declaration
bool ICollection<KeyValuePair<string, JToken>>.Contains(KeyValuePair<string, JToken> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.String, JToken> | item |
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<KeyValuePair<String, JToken>>.CopyTo(KeyValuePair<String, JToken>[], Int32)
Declaration
void ICollection<KeyValuePair<string, JToken>>.CopyTo(KeyValuePair<string, JToken>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.String, JToken>[] | array | |
System.Int32 | arrayIndex |
ICollection<KeyValuePair<String, JToken>>.IsReadOnly
Declaration
bool ICollection<KeyValuePair<string, JToken>>.IsReadOnly { get; }
Returns
Type | Description |
---|---|
System.Boolean |
ICollection<KeyValuePair<String, JToken>>.Remove(KeyValuePair<String, JToken>)
Declaration
bool ICollection<KeyValuePair<string, JToken>>.Remove(KeyValuePair<string, JToken> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.String, JToken> | item |
Returns
Type | Description |
---|---|
System.Boolean |
IDictionary<String, JToken>.ContainsKey(String)
Declaration
bool IDictionary<string, JToken>.ContainsKey(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key |
Returns
Type | Description |
---|---|
System.Boolean |
IDictionary<String, JToken>.Keys
Declaration
ICollection<string> IDictionary<string, JToken>.Keys { get; }
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<System.String> |
IDictionary<String, JToken>.Values
Declaration
ICollection<JToken> IDictionary<string, JToken>.Values { get; }
Returns
Type | Description |
---|---|
System.Collections.Generic.ICollection<JToken> |
ICustomTypeDescriptor.GetAttributes()
Returns a collection of custom attributes for this instance of a component.
Declaration
AttributeCollection ICustomTypeDescriptor.GetAttributes()
Returns
Type | Description |
---|---|
System.ComponentModel.AttributeCollection | An System.ComponentModel.AttributeCollection containing the attributes for this object. |
ICustomTypeDescriptor.GetClassName()
Returns the class name of this instance of a component.
Declaration
string ICustomTypeDescriptor.GetClassName()
Returns
Type | Description |
---|---|
System.String | The class name of the object, or null if the class does not have a name. |
ICustomTypeDescriptor.GetComponentName()
Returns the name of this instance of a component.
Declaration
string ICustomTypeDescriptor.GetComponentName()
Returns
Type | Description |
---|---|
System.String | The name of the object, or null if the object does not have a name. |
ICustomTypeDescriptor.GetConverter()
Returns a type converter for this instance of a component.
Declaration
TypeConverter ICustomTypeDescriptor.GetConverter()
Returns
Type | Description |
---|---|
System.ComponentModel.TypeConverter | A System.ComponentModel.TypeConverter that is the converter for this object, or null if there is no System.ComponentModel.TypeConverter for this object. |
ICustomTypeDescriptor.GetDefaultEvent()
Returns the default event for this instance of a component.
Declaration
EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
Returns
Type | Description |
---|---|
System.ComponentModel.EventDescriptor | An System.ComponentModel.EventDescriptor that represents the default event for this object, or null if this object does not have events. |
ICustomTypeDescriptor.GetDefaultProperty()
Returns the default property for this instance of a component.
Declaration
PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
Returns
Type | Description |
---|---|
System.ComponentModel.PropertyDescriptor | A System.ComponentModel.PropertyDescriptor that represents the default property for this object, or null if this object does not have properties. |
ICustomTypeDescriptor.GetEditor(Type)
Returns an editor of the specified type for this instance of a component.
Declaration
object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | editorBaseType | A System.Type that represents the editor for this object. |
Returns
Type | Description |
---|---|
System.Object | An System.Object of the specified type that is the editor for this object, or null if the editor cannot be found. |
ICustomTypeDescriptor.GetEvents()
Returns the events for this instance of a component.
Declaration
EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
Returns
Type | Description |
---|---|
System.ComponentModel.EventDescriptorCollection | An System.ComponentModel.EventDescriptorCollection that represents the events for this component instance. |
ICustomTypeDescriptor.GetEvents(Attribute[])
Returns the events for this instance of a component using the specified attribute array as a filter.
Declaration
EventDescriptorCollection ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
Parameters
Type | Name | Description |
---|---|---|
System.Attribute[] | attributes | An array of type System.Attribute that is used as a filter. |
Returns
Type | Description |
---|---|
System.ComponentModel.EventDescriptorCollection | An System.ComponentModel.EventDescriptorCollection that represents the filtered events for this component instance. |
ICustomTypeDescriptor.GetProperties()
Returns the properties for this instance of a component.
Declaration
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
Returns
Type | Description |
---|---|
System.ComponentModel.PropertyDescriptorCollection | A System.ComponentModel.PropertyDescriptorCollection that represents the properties for this component instance. |
ICustomTypeDescriptor.GetProperties(Attribute[])
Returns the properties for this instance of a component using the attribute array as a filter.
Declaration
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
Parameters
Type | Name | Description |
---|---|---|
System.Attribute[] | attributes | An array of type System.Attribute that is used as a filter. |
Returns
Type | Description |
---|---|
System.ComponentModel.PropertyDescriptorCollection | A System.ComponentModel.PropertyDescriptorCollection that represents the filtered properties for this component instance. |
ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor)
Returns an object that contains the property described by the specified property descriptor.
Declaration
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.PropertyDescriptor | pd | A System.ComponentModel.PropertyDescriptor that represents the property whose owner is to be found. |
Returns
Type | Description |
---|---|
System.Object | An System.Object that represents the owner of the specified property. |