Class JsonHelper
Helper class for Json related operations.
Inherited Members
Namespace: DataWeb.Data
Assembly: DataWeb.Core.dll
Syntax
public static class JsonHelper
Methods
DeserializeCultureItems(string)
Deserializes the culture items from structured data.
Declaration
public static List<Form.CultureItem> DeserializeCultureItems(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The JSON string containing the localized values. |
Returns
| Type | Description |
|---|---|
| List<Form.CultureItem> | The deserialized culture items.. |
GetLocalizedValue(string, string, string)
Returns the localized value for the given culture and fallback culture.
Declaration
public static string GetLocalizedValue(string value, string culture, string fallbackCulture = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The JSON string containing the localized values. |
| string | culture | The culture for which to get the localized value. |
| string | fallbackCulture | The fallback culture to use if the requested culture is not found. |
Returns
| Type | Description |
|---|---|
| string | The localized value for the given culture and fallback culture. |
GetPropertyAsBoolean(JsonElement, string)
Gets the value of the specified property in the provided JsonElement as a bool if it exists and is not null.
Declaration
public static bool? GetPropertyAsBoolean(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JsonElement that contains the property. |
| string | propertyName | The name of the property to retrieve. |
Returns
| Type | Description |
|---|---|
| bool? | The value of the specified property as a bool if it exists and is not null, or null otherwise. |
GetPropertyAsDateTime(JsonElement, string)
Gets the specified property value as a nullable DateTime.
Declaration
public static DateTime? GetPropertyAsDateTime(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JSON element containing the property. |
| string | propertyName | The name of the property to get. |
Returns
| Type | Description |
|---|---|
| DateTime? | The value of the property as a nullable DateTime, or null if the property does not exist or is null. |
GetPropertyAsDateTimeOffset(JsonElement, string)
Gets the specified property value as a nullable DateTimeOffset.
Declaration
public static DateTimeOffset? GetPropertyAsDateTimeOffset(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JSON element containing the property. |
| string | propertyName | The name of the property to get. |
Returns
| Type | Description |
|---|---|
| DateTimeOffset? | The value of the property as a nullable DateTimeOffset, or null if the property does not exist or is null. |
GetPropertyAsDecimal(JsonElement, string)
Gets the value of the specified property in the provided JsonElement as a decimal if it exists and is not null.
Declaration
public static decimal? GetPropertyAsDecimal(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JsonElement that contains the property. |
| string | propertyName | The name of the property to retrieve. |
Returns
| Type | Description |
|---|---|
| decimal? | The value of the specified property as a decimal if it exists and is not null, or null otherwise. |
GetPropertyAsDouble(JsonElement, string)
Gets the specified property value as a nullable double.
Declaration
public static double? GetPropertyAsDouble(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JSON element containing the property. |
| string | propertyName | The name of the property to get. |
Returns
| Type | Description |
|---|---|
| double? | The value of the property as a nullable double, or null if the property does not exist or is null. |
GetPropertyAsInt(JsonElement, string)
Gets the value of the specified property in the provided JsonElement as an int if it exists and is not null.
Declaration
public static int? GetPropertyAsInt(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JsonElement that contains the property. |
| string | propertyName | The name of the property to retrieve. |
Returns
| Type | Description |
|---|---|
| int? | The value of the specified property as an int if it exists and is not null, or null otherwise. |
GetPropertyAsLong(JsonElement, string)
Gets the value of the specified property in the provided JsonElement as a long if it exists and is not null.
Declaration
public static long? GetPropertyAsLong(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JsonElement that contains the property. |
| string | propertyName | The name of the property to retrieve. |
Returns
| Type | Description |
|---|---|
| long? | The value of the specified property as a long if it exists and is not null, or null otherwise. |
GetPropertyAsRawText(JsonElement, string)
Gets the specified property value as a raw JSON string.
Declaration
public static string GetPropertyAsRawText(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JSON element containing the property. |
| string | propertyName | The name of the property to get. |
Returns
| Type | Description |
|---|---|
| string | The value of the property as a raw JSON string, or null if the property does not exist or is null. |
GetPropertyAsString(JsonElement, string)
Gets the specified property value as a string.
Declaration
public static string GetPropertyAsString(JsonElement jelement, string propertyName)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | The JSON element containing the property. |
| string | propertyName | The name of the property to get. |
Returns
| Type | Description |
|---|---|
| string | The value of the property as a string, or null if the property does not exist or is null. |
GetValueAsObject(JsonElement, bool)
Returns a C# object based on the type of the JsonElement passed as parameter.
Declaration
public static object GetValueAsObject(JsonElement jelement, bool isIndentedSerialization = false)
Parameters
| Type | Name | Description |
|---|---|---|
| JsonElement | jelement | JsonElement to parse. |
| bool | isIndentedSerialization | Serialize structured data using indented format instead of raw text in order to mantain format for modified fields check |
Returns
| Type | Description |
|---|---|
| object | An object with the value of the parsed JsonElement. |
Prettify(string)
Prettify an existing JSON string using default serialization options.
Declaration
public static string Prettify(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The json string to be prettified. |
Returns
| Type | Description |
|---|---|
| string | The prettified JSON string. |
SerializeStructuredData(object)
Serializes an object to a JSON string using default serialization options.
Declaration
public static string SerializeStructuredData(object value)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The object to serialize. |
Returns
| Type | Description |
|---|---|
| string | The serialized JSON string. |