Class JsonExtensions
public static class JsonExtensions
- Inheritance
-
JsonExtensions
- Inherited Members
Methods
AddJsonProperty<TPropertyType>(string, string, TPropertyType)
Adds a new property with the specified name and value to the given JSON string.
public static string AddJsonProperty<TPropertyType>(this string jsonText, string propertyName, TPropertyType propertyValue)
Parameters
jsonTextstringThe original JSON string.
propertyNamestringThe name of the property to add.
propertyValueTPropertyTypeThe value of the property to add.
Returns
- string
A new JSON string with the added property.
Type Parameters
TPropertyTypeThe type of the property value to add. If it is string in JSON format, it is added as another JSON node.
CombineWithJson(string, string)
Merges two JSON objects represented as strings.
The otherJson object will overwrite existing properties in baseJson
or add new ones.
public static string CombineWithJson(this string baseJson, string otherJson)
Parameters
baseJsonstringThe original JSON string to be merged into.
otherJsonstringThe JSON string containing properties to merge into
baseJson.
Returns
- string
A new JSON string representing the merged result of
baseJsonandotherJson.
RemoveJsonProperty(string, string)
Removes a property with the specified name from the given JSON string.
public static string RemoveJsonProperty(this string jsonText, string propertyName)
Parameters
Returns
- string
A new JSON string without the specified property.
ToExpando(string)
Parses given text (in JSON structure) to case-insensitive expando object (CaseInsensitiveExpandoObject).
public static CaseInsensitiveExpandoObject ToExpando(this string jsonText)
Parameters
jsonTextstringText to be parsed into case-insensitive expando object (CaseInsensitiveExpandoObject).
Returns
- CaseInsensitiveExpandoObject
CaseInsensitiveExpandoObject representation of JSON stored in
jsonText.
ToJson(string)
Parses given text to Newtonsoft.Json.Linq.JObject form.
public static JObject ToJson(this string text)
Parameters
textstringText to be parsed into Newtonsoft.Json.Linq.JObject.
Returns
- JObject
Newtonsoft.Json.Linq.JObject representation of JSON within
text.
ToJsonString(object)
Serializes object to string in JSON structure.
public static string ToJsonString(this object obj)
Parameters
Returns
To<TResult>(string)
Convert JSON string to TResult.
public static TResult? To<TResult>(this string jsonText)
Parameters
jsonTextstringString in JSON structure, object should be extracted from.
Returns
- TResult
jsonTextin aTResultform.
Type Parameters
TResultType which JSON string will be deserialized to.