Class JsonConvert
- Namespace
- Newtonsoft.Json
- Assembly
- Newtonsoft.Json.dll
Provides methods for converting between common language runtime types and JSON types.
public static class JsonConvert
- Inheritance
-
JsonConvert
- Inherited Members
Fields
False
Represents JavaScript's boolean value false as a string. This field is read-only.
public static readonly string False
Field Value
NaN
Represents JavaScript's NaN as a string. This field is read-only.
public static readonly string NaN
Field Value
NegativeInfinity
Represents JavaScript's negative infinity as a string. This field is read-only.
public static readonly string NegativeInfinity
Field Value
Null
Represents JavaScript's null as a string. This field is read-only.
public static readonly string Null
Field Value
PositiveInfinity
Represents JavaScript's positive infinity as a string. This field is read-only.
public static readonly string PositiveInfinity
Field Value
True
Represents JavaScript's boolean value true as a string. This field is read-only.
public static readonly string True
Field Value
Undefined
Represents JavaScript's undefined as a string. This field is read-only.
public static readonly string Undefined
Field Value
Methods
DeserializeAnonymousType<T>(string, T)
Deserializes the JSON to the given anonymous type.
public static T DeserializeAnonymousType<T>(string value, T anonymousTypeObject)
Parameters
valuestringThe JSON to deserialize.
anonymousTypeObjectTThe anonymous type object.
Returns
- T
The deserialized anonymous type from the JSON string.
Type Parameters
TThe anonymous type to deserialize to. This can't be specified traditionally and must be infered from the anonymous type passed as a parameter.
DeserializeObject(string)
Deserializes the JSON to a .NET object.
public static object DeserializeObject(string value)
Parameters
valuestringThe JSON to deserialize.
Returns
- object
The deserialized object from the Json string.
DeserializeObject(string, JsonSerializerSettings)
Deserializes the JSON to a .NET object.
public static object DeserializeObject(string value, JsonSerializerSettings settings)
Parameters
valuestringThe JSON to deserialize.
settingsJsonSerializerSettingsThe JsonSerializerSettings used to deserialize the object. If this is null, default serialization settings will be is used.
Returns
- object
The deserialized object from the JSON string.
DeserializeObject(string, Type)
Deserializes the JSON to the specified .NET type.
public static object DeserializeObject(string value, Type type)
Parameters
Returns
- object
The deserialized object from the Json string.
DeserializeObject(string, Type, params JsonConverter[])
Deserializes the JSON to the specified .NET type.
public static object DeserializeObject(string value, Type type, params JsonConverter[] converters)
Parameters
valuestringThe JSON to deserialize.
typeTypeThe type of the object to deserialize.
convertersJsonConverter[]Converters to use while deserializing.
Returns
- object
The deserialized object from the JSON string.
DeserializeObject(string, Type, JsonSerializerSettings)
Deserializes the JSON to the specified .NET type.
public static object DeserializeObject(string value, Type type, JsonSerializerSettings settings)
Parameters
valuestringThe JSON to deserialize.
typeTypeThe type of the object to deserialize to.
settingsJsonSerializerSettingsThe JsonSerializerSettings used to deserialize the object. If this is null, default serialization settings will be is used.
Returns
- object
The deserialized object from the JSON string.
DeserializeObject<T>(string)
Deserializes the JSON to the specified .NET type.
public static T DeserializeObject<T>(string value)
Parameters
valuestringThe JSON to deserialize.
Returns
- T
The deserialized object from the Json string.
Type Parameters
TThe type of the object to deserialize to.
DeserializeObject<T>(string, params JsonConverter[])
Deserializes the JSON to the specified .NET type.
public static T DeserializeObject<T>(string value, params JsonConverter[] converters)
Parameters
valuestringThe JSON to deserialize.
convertersJsonConverter[]Converters to use while deserializing.
Returns
- T
The deserialized object from the JSON string.
Type Parameters
TThe type of the object to deserialize to.
DeserializeObject<T>(string, JsonSerializerSettings)
Deserializes the JSON to the specified .NET type.
public static T DeserializeObject<T>(string value, JsonSerializerSettings settings)
Parameters
valuestringThe object to deserialize.
settingsJsonSerializerSettingsThe JsonSerializerSettings used to deserialize the object. If this is null, default serialization settings will be is used.
Returns
- T
The deserialized object from the JSON string.
Type Parameters
TThe type of the object to deserialize to.
DeserializeXNode(string)
Deserializes the System.Xml.Linq.XNode from a JSON string.
public static XDocument DeserializeXNode(string value)
Parameters
valuestringThe JSON string.
Returns
- XDocument
The deserialized XNode
DeserializeXNode(string, string)
Deserializes the System.Xml.Linq.XNode from a JSON string nested in a root elment.
public static XDocument DeserializeXNode(string value, string deserializeRootElementName)
Parameters
valuestringThe JSON string.
deserializeRootElementNamestringThe name of the root element to append when deserializing.
Returns
- XDocument
The deserialized XNode
DeserializeXNode(string, string, bool)
Deserializes the System.Xml.Linq.XNode from a JSON string nested in a root elment.
public static XDocument DeserializeXNode(string value, string deserializeRootElementName, bool writeArrayAttribute)
Parameters
valuestringThe JSON string.
deserializeRootElementNamestringThe name of the root element to append when deserializing.
writeArrayAttributeboolA flag to indicate whether to write the Json.NET array attribute. This attribute helps preserve arrays when converting the written XML back to JSON.
Returns
- XDocument
The deserialized XNode
DeserializeXmlNode(string)
Deserializes the XmlNode from a JSON string.
public static XmlDocument DeserializeXmlNode(string value)
Parameters
valuestringThe JSON string.
Returns
- XmlDocument
The deserialized XmlNode
DeserializeXmlNode(string, string)
Deserializes the XmlNode from a JSON string nested in a root elment.
public static XmlDocument DeserializeXmlNode(string value, string deserializeRootElementName)
Parameters
valuestringThe JSON string.
deserializeRootElementNamestringThe name of the root element to append when deserializing.
Returns
- XmlDocument
The deserialized XmlNode
DeserializeXmlNode(string, string, bool)
Deserializes the XmlNode from a JSON string nested in a root elment.
public static XmlDocument DeserializeXmlNode(string value, string deserializeRootElementName, bool writeArrayAttribute)
Parameters
valuestringThe JSON string.
deserializeRootElementNamestringThe name of the root element to append when deserializing.
writeArrayAttributeboolA flag to indicate whether to write the Json.NET array attribute. This attribute helps preserve arrays when converting the written XML back to JSON.
Returns
- XmlDocument
The deserialized XmlNode
PopulateObject(string, object)
Populates the object with values from the JSON string.
public static void PopulateObject(string value, object target)
Parameters
valuestringThe JSON to populate values from.
targetobjectThe target object to populate values onto.
PopulateObject(string, object, JsonSerializerSettings)
Populates the object with values from the JSON string.
public static void PopulateObject(string value, object target, JsonSerializerSettings settings)
Parameters
valuestringThe JSON to populate values from.
targetobjectThe target object to populate values onto.
settingsJsonSerializerSettingsThe JsonSerializerSettings used to deserialize the object. If this is null, default serialization settings will be is used.
SerializeObject(object)
Serializes the specified object to a JSON string.
public static string SerializeObject(object value)
Parameters
valueobjectThe object to serialize.
Returns
- string
A JSON string representation of the object.
SerializeObject(object, Formatting)
Serializes the specified object to a JSON string.
public static string SerializeObject(object value, Formatting formatting)
Parameters
valueobjectThe object to serialize.
formattingFormattingIndicates how the output is formatted.
Returns
- string
A JSON string representation of the object.
SerializeObject(object, Formatting, params JsonConverter[])
Serializes the specified object to a JSON string using a collection of JsonConverter.
public static string SerializeObject(object value, Formatting formatting, params JsonConverter[] converters)
Parameters
valueobjectThe object to serialize.
formattingFormattingIndicates how the output is formatted.
convertersJsonConverter[]A collection converters used while serializing.
Returns
- string
A JSON string representation of the object.
SerializeObject(object, Formatting, JsonSerializerSettings)
Serializes the specified object to a JSON string using a collection of JsonConverter.
public static string SerializeObject(object value, Formatting formatting, JsonSerializerSettings settings)
Parameters
valueobjectThe object to serialize.
formattingFormattingIndicates how the output is formatted.
settingsJsonSerializerSettingsThe JsonSerializerSettings used to serialize the object. If this is null, default serialization settings will be is used.
Returns
- string
A JSON string representation of the object.
SerializeObject(object, params JsonConverter[])
Serializes the specified object to a JSON string using a collection of JsonConverter.
public static string SerializeObject(object value, params JsonConverter[] converters)
Parameters
valueobjectThe object to serialize.
convertersJsonConverter[]A collection converters used while serializing.
Returns
- string
A JSON string representation of the object.
SerializeXNode(XObject)
Serializes the System.Xml.Linq.XNode to a JSON string.
public static string SerializeXNode(XObject node)
Parameters
nodeXObjectThe node to convert to JSON.
Returns
- string
A JSON string of the XNode.
SerializeXNode(XObject, Formatting)
Serializes the System.Xml.Linq.XNode to a JSON string.
public static string SerializeXNode(XObject node, Formatting formatting)
Parameters
nodeXObjectThe node to convert to JSON.
formattingFormattingIndicates how the output is formatted.
Returns
- string
A JSON string of the XNode.
SerializeXNode(XObject, Formatting, bool)
Serializes the System.Xml.Linq.XNode to a JSON string.
public static string SerializeXNode(XObject node, Formatting formatting, bool omitRootObject)
Parameters
nodeXObjectThe node to serialize.
formattingFormattingIndicates how the output is formatted.
omitRootObjectboolOmits writing the root object.
Returns
- string
A JSON string of the XNode.
SerializeXmlNode(XmlNode)
Serializes the XML node to a JSON string.
public static string SerializeXmlNode(XmlNode node)
Parameters
nodeXmlNodeThe node to serialize.
Returns
- string
A JSON string of the XmlNode.
SerializeXmlNode(XmlNode, Formatting)
Serializes the XML node to a JSON string.
public static string SerializeXmlNode(XmlNode node, Formatting formatting)
Parameters
nodeXmlNodeThe node to serialize.
formattingFormattingIndicates how the output is formatted.
Returns
- string
A JSON string of the XmlNode.
SerializeXmlNode(XmlNode, Formatting, bool)
Serializes the XML node to a JSON string.
public static string SerializeXmlNode(XmlNode node, Formatting formatting, bool omitRootObject)
Parameters
nodeXmlNodeThe node to serialize.
formattingFormattingIndicates how the output is formatted.
omitRootObjectboolOmits writing the root object.
Returns
- string
A JSON string of the XmlNode.
ToString(bool)
Converts the bool to its JSON string representation.
public static string ToString(bool value)
Parameters
valueboolThe value to convert.
Returns
ToString(byte)
Converts the byte to its JSON string representation.
public static string ToString(byte value)
Parameters
valuebyteThe value to convert.
Returns
ToString(char)
Converts the char to its JSON string representation.
public static string ToString(char value)
Parameters
valuecharThe value to convert.
Returns
ToString(DateTime)
Converts the DateTime to its JSON string representation.
public static string ToString(DateTime value)
Parameters
valueDateTimeThe value to convert.
Returns
ToString(DateTimeOffset)
Converts the DateTimeOffset to its JSON string representation.
public static string ToString(DateTimeOffset value)
Parameters
valueDateTimeOffsetThe value to convert.
Returns
- string
A JSON string representation of the DateTimeOffset.
ToString(decimal)
Converts the decimal to its JSON string representation.
public static string ToString(decimal value)
Parameters
valuedecimalThe value to convert.
Returns
ToString(double)
Converts the double to its JSON string representation.
public static string ToString(double value)
Parameters
valuedoubleThe value to convert.
Returns
ToString(Enum)
Converts the Enum to its JSON string representation.
public static string ToString(Enum value)
Parameters
valueEnumThe value to convert.
Returns
ToString(Guid)
Converts the Guid to its JSON string representation.
public static string ToString(Guid value)
Parameters
valueGuidThe value to convert.
Returns
ToString(short)
Converts the short to its JSON string representation.
public static string ToString(short value)
Parameters
valueshortThe value to convert.
Returns
ToString(int)
Converts the int to its JSON string representation.
public static string ToString(int value)
Parameters
valueintThe value to convert.
Returns
ToString(long)
Converts the long to its JSON string representation.
public static string ToString(long value)
Parameters
valuelongThe value to convert.
Returns
ToString(object)
Converts the object to its JSON string representation.
public static string ToString(object value)
Parameters
valueobjectThe value to convert.
Returns
ToString(sbyte)
Converts the sbyte to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(sbyte value)
Parameters
valuesbyteThe value to convert.
Returns
ToString(float)
Converts the float to its JSON string representation.
public static string ToString(float value)
Parameters
valuefloatThe value to convert.
Returns
ToString(string)
Converts the string to its JSON string representation.
public static string ToString(string value)
Parameters
valuestringThe value to convert.
Returns
ToString(string, char)
Converts the string to its JSON string representation.
public static string ToString(string value, char delimter)
Parameters
Returns
ToString(TimeSpan)
Converts the TimeSpan to its JSON string representation.
public static string ToString(TimeSpan value)
Parameters
valueTimeSpanThe value to convert.
Returns
ToString(ushort)
Converts the ushort to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(ushort value)
Parameters
valueushortThe value to convert.
Returns
ToString(uint)
Converts the uint to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(uint value)
Parameters
valueuintThe value to convert.
Returns
ToString(ulong)
Converts the ulong to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(ulong value)
Parameters
valueulongThe value to convert.
Returns
ToString(Uri)
Converts the System.Uri to its JSON string representation.
public static string ToString(Uri value)
Parameters
valueUriThe value to convert.
Returns
- string
A JSON string representation of the System.Uri.