Class Json
Serializes and deserializes objects into and from JSON documents.
Inheritance
Inherited Members
Namespace: Terrasoft.Common.Json
Assembly: Terrasoft.Common.dll
Syntax
public static class Json
Methods
Deserialize(String)
Deserializes the JSON to an object.
Declaration
public static object Deserialize(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The JSON string. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Deserialize(String, Type)
Deserializes the JSON to an object.
Declaration
public static object Deserialize(string value, Type type)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The JSON string. |
System.Type | type | Type of the deserialized object. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Deserialize(String, Type, IList<JsonConverter>)
Deserializes the JSON to an object.
Declaration
public static object Deserialize(string value, Type type, IList<JsonConverter> converters)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The JSON string. |
System.Type | type | Type of the deserialized object. |
System.Collections.Generic.IList<JsonConverter> | converters | Json converters that will be used during serialization. |
Returns
Type | Description |
---|---|
System.Object | The deserialized object. |
Deserialize<T>(String)
Deserializes the JSON to the specified type.
Declaration
public static T Deserialize<T>(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The JSON string. |
Returns
Type | Description |
---|---|
T | The deserialized object. |
Type Parameters
Name | Description |
---|---|
T |
Deserialize<T>(String, JsonSerializerSettings)
Deserializes the JSON to the specified .NET type using Newtonsoft.Json.JsonSerializerSettings.
Declaration
public static T Deserialize<T>(string value, JsonSerializerSettings settings)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The object to deserialize. |
JsonSerializerSettings | settings | The Newtonsoft.Json.JsonSerializerSettings used to deserialize the object.
If this is |
Returns
Type | Description |
---|---|
T | The deserialized object from the JSON string. |
Type Parameters
Name | Description |
---|---|
T | The type of the object to deserialize to. |
DeserializeDictionary(String)
Declaration
public static Dictionary<string, string> DeserializeDictionary(string source)
Parameters
Type | Name | Description |
---|---|---|
System.String | source |
Returns
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.String, System.String> |
DeserializeXmlNode(String)
Deserializes the XmlNode from a JSON string.
Declaration
public static XmlNode DeserializeXmlNode(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value | The JSON string. |
Returns
Type | Description |
---|---|
System.Xml.XmlNode | Instance of the System.Xml.XmlNode type. |
FindPropertyByName(JObject, String)
Declaration
public static JProperty FindPropertyByName(this JObject source, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
JObject | source | |
System.String | propertyName |
Returns
Type | Description |
---|---|
JProperty |
FormatJsonString(String, Newtonsoft.Json.Formatting)
Returns formatted JSON string.
Declaration
public static string FormatJsonString(string source, Newtonsoft.Json.Formatting formatting)
Parameters
Type | Name | Description |
---|---|---|
System.String | source | The JSON string. |
Newtonsoft.Json.Formatting | formatting | Formatting information. |
Returns
Type | Description |
---|---|
System.String | Formatted JSON string. |
GetPropertyByName(JObject, String)
Declaration
public static JProperty GetPropertyByName(this JObject source, string propertyName)
Parameters
Type | Name | Description |
---|---|---|
JObject | source | |
System.String | propertyName |
Returns
Type | Description |
---|---|
JProperty |
Serialize(Boolean)
Serializes the specified logical value and writes the JSON structure.
Declaration
public static string Serialize(bool obj)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | obj | The logical value. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Guid)
Serializes the specified unique identifier and writes the JSON structure.
Declaration
public static string Serialize(Guid obj)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | obj | The unique identifier. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Int32)
Serializes the specified integer value and writes the JSON structure.
Declaration
public static string Serialize(int obj)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | obj | The integer value. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Object)
Serializes the specified object and writes the JSON structure.
Declaration
public static string Serialize(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to serialize. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Object, JsonConverter)
Serializes the specified object and writes the JSON structure.
Declaration
public static string Serialize(object obj, JsonConverter converter)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to serialize. |
JsonConverter | converter | Instance that converts an object to and from JSON. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Object, Boolean)
Serializes the specified object and writes the JSON structure with quoteName flag.
Declaration
public static string Serialize(object obj, bool quoteName)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to serialize. |
System.Boolean | quoteName | A value indicating whether object names will be surrounded with quotes. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(Object, Boolean, TypeNameHandling)
Serializes the specified object and writes the JSON structure with quoteName flag and specified type name handling.
Declaration
public static string Serialize(object obj, bool quoteName, TypeNameHandling typeNameHandling)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to serialize. |
System.Boolean | quoteName | A value indicating whether object names will be surrounded with quotes. |
TypeNameHandling | typeNameHandling | A value of |
Returns
Type | Description |
---|---|
System.String | The serialized object. |
Serialize(String)
Serializes the specified string value and writes the JSON structure.
Declaration
public static string Serialize(string obj)
Parameters
Type | Name | Description |
---|---|---|
System.String | obj | The string value. |
Returns
Type | Description |
---|---|
System.String | The serialized object. |