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
value
stringThe JSON to deserialize.
anonymousTypeObject
TThe anonymous type object.
Returns
- T
The deserialized anonymous type from the JSON string.
Type Parameters
T
The 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
value
stringThe 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
value
stringThe JSON to deserialize.
settings
JsonSerializerSettingsThe 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
value
stringThe JSON to deserialize.
type
TypeThe type of the object to deserialize.
converters
JsonConverter[]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
value
stringThe JSON to deserialize.
type
TypeThe type of the object to deserialize to.
settings
JsonSerializerSettingsThe 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
value
stringThe JSON to deserialize.
Returns
- T
The deserialized object from the Json string.
Type Parameters
T
The 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
value
stringThe JSON to deserialize.
converters
JsonConverter[]Converters to use while deserializing.
Returns
- T
The deserialized object from the JSON string.
Type Parameters
T
The 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
value
stringThe object to deserialize.
settings
JsonSerializerSettingsThe 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
T
The 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
value
stringThe 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
value
stringThe JSON string.
deserializeRootElementName
stringThe 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
value
stringThe JSON string.
deserializeRootElementName
stringThe name of the root element to append when deserializing.
writeArrayAttribute
boolA 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
value
stringThe 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
value
stringThe JSON string.
deserializeRootElementName
stringThe 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
value
stringThe JSON string.
deserializeRootElementName
stringThe name of the root element to append when deserializing.
writeArrayAttribute
boolA 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
value
stringThe JSON to populate values from.
target
objectThe 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
value
stringThe JSON to populate values from.
target
objectThe target object to populate values onto.
settings
JsonSerializerSettingsThe 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
value
objectThe 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
value
objectThe object to serialize.
formatting
FormattingIndicates 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
value
objectThe object to serialize.
formatting
FormattingIndicates how the output is formatted.
converters
JsonConverter[]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
value
objectThe object to serialize.
formatting
FormattingIndicates how the output is formatted.
settings
JsonSerializerSettingsThe 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
value
objectThe object to serialize.
converters
JsonConverter[]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
node
XObjectThe 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
node
XObjectThe node to convert to JSON.
formatting
FormattingIndicates 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
node
XObjectThe node to serialize.
formatting
FormattingIndicates how the output is formatted.
omitRootObject
boolOmits 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
node
XmlNodeThe 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
node
XmlNodeThe node to serialize.
formatting
FormattingIndicates 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
node
XmlNodeThe node to serialize.
formatting
FormattingIndicates how the output is formatted.
omitRootObject
boolOmits 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
value
boolThe value to convert.
Returns
ToString(byte)
Converts the byte to its JSON string representation.
public static string ToString(byte value)
Parameters
value
byteThe value to convert.
Returns
ToString(char)
Converts the char to its JSON string representation.
public static string ToString(char value)
Parameters
value
charThe value to convert.
Returns
ToString(DateTime)
Converts the DateTime to its JSON string representation.
public static string ToString(DateTime value)
Parameters
value
DateTimeThe value to convert.
Returns
ToString(DateTimeOffset)
Converts the DateTimeOffset to its JSON string representation.
public static string ToString(DateTimeOffset value)
Parameters
value
DateTimeOffsetThe 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
value
decimalThe value to convert.
Returns
ToString(double)
Converts the double to its JSON string representation.
public static string ToString(double value)
Parameters
value
doubleThe value to convert.
Returns
ToString(Enum)
Converts the Enum to its JSON string representation.
public static string ToString(Enum value)
Parameters
value
EnumThe value to convert.
Returns
ToString(Guid)
Converts the Guid to its JSON string representation.
public static string ToString(Guid value)
Parameters
value
GuidThe value to convert.
Returns
ToString(short)
Converts the short to its JSON string representation.
public static string ToString(short value)
Parameters
value
shortThe value to convert.
Returns
ToString(int)
Converts the int to its JSON string representation.
public static string ToString(int value)
Parameters
value
intThe value to convert.
Returns
ToString(long)
Converts the long to its JSON string representation.
public static string ToString(long value)
Parameters
value
longThe value to convert.
Returns
ToString(object)
Converts the object to its JSON string representation.
public static string ToString(object value)
Parameters
value
objectThe value to convert.
Returns
ToString(sbyte)
Converts the sbyte to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(sbyte value)
Parameters
value
sbyteThe value to convert.
Returns
ToString(float)
Converts the float to its JSON string representation.
public static string ToString(float value)
Parameters
value
floatThe value to convert.
Returns
ToString(string)
Converts the string to its JSON string representation.
public static string ToString(string value)
Parameters
value
stringThe 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
value
TimeSpanThe value to convert.
Returns
ToString(ushort)
Converts the ushort to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(ushort value)
Parameters
value
ushortThe value to convert.
Returns
ToString(uint)
Converts the uint to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(uint value)
Parameters
value
uintThe value to convert.
Returns
ToString(ulong)
Converts the ulong to its JSON string representation.
[CLSCompliant(false)]
public static string ToString(ulong value)
Parameters
value
ulongThe value to convert.
Returns
ToString(Uri)
Converts the System.Uri to its JSON string representation.
public static string ToString(Uri value)
Parameters
value
UriThe value to convert.
Returns
- string
A JSON string representation of the System.Uri.