JsonHelper
Provides helper methods for JSON serialization and deserialization.
メソッド
public static void CheckExpectedToken(JsonReader reader, JsonToken token)
JsonHelper.CheckExpectedToken(reader, token)
Checks that the current token of the JSON reader matches the expected token.
- reader
- The JSON reader.
- token
- The expected JSON token.
public static JsonSerializerSettings CreateJsonSerializerSettings()
result = JsonHelper.CreateJsonSerializerSettings()
Creates and configures a new instance of JsonSerializerSettings.
戻り値: The configured JsonSerializerSettings instance.
public static object DeserializeObject(string content, Type type)
result = JsonHelper.DeserializeObject(content, type)
Deserializes the JSON string into an object of the specified type.
- content
- The JSON string.
- type
- The target type.
戻り値: The deserialized object.
public static object DeserializeObject(JToken token, Type type)
result = JsonHelper.DeserializeObject(token, type)
Deserializes the JSON token into an object of the specified type.
- token
- The JSON token.
- type
- The target type.
戻り値: The deserialized object.
public static T DeserializeObject<T>(string content)
result = JsonHelper.DeserializeObject(content)
Deserializes the JSON string into an object of type T.
- content
- The JSON string.
戻り値: The deserialized object.
public static T DeserializeObject<T>(JToken token)
result = JsonHelper.DeserializeObject(token)
Deserializes the JSON token into an object of type T.
- token
- The JSON token.
戻り値: The deserialized object.
public static object FromJson(string json, Type type)
result = JsonHelper.FromJson(json, type)
Deserializes the JSON string into an object using Newtonsoft.Json.
- json
- The JSON string.
- type
- The target type.
戻り値: The deserialized object.
public static Task ReadWithCheckAsync(JsonReader reader, CancellationToken cancellationToken)
result = JsonHelper.ReadWithCheckAsync(reader, cancellationToken)
Asynchronously reads the next token from the JSON reader and checks for end-of-file.
- reader
- The JSON reader.
- cancellationToken
- A cancellation token.
戻り値: A task that represents the asynchronous read operation.
public static byte[] SkipBom(byte[] array)
result = JsonHelper.SkipBom(array)
Skips the Byte Order Mark (BOM) from the beginning of a byte array if present.
- array
- The byte array.
戻り値: The byte array without the BOM.
public static string SkipBom(string str)
result = JsonHelper.SkipBom(str)
Removes a leading Unicode byte order mark (BOM, U+FEFF) from the specified string, if present.
- str
- The input string (can be null or empty).
戻り値: The input string without a leading BOM character; if the string is null, empty, or does not start with a BOM, the original value is returned.
public static string ToJson(object obj, bool indent)
result = JsonHelper.ToJson(obj, indent)
Serializes the object into a JSON string with optional indentation.
- obj
- The object to serialize.
- indent
- True to format the JSON string; otherwise, false.
戻り値: The JSON string.
public static string ToJson(object obj, bool indent, JsonSerializerSettings settings)
result = JsonHelper.ToJson(obj, indent, settings)
Serializes the object into a JSON string with optional indentation and custom serializer settings.
- obj
- The object to serialize.
- indent
- True to format the JSON string; otherwise, false.
- settings
- The JSON serializer settings.
戻り値: The JSON string.
フィールド
public static readonly Encoding UTF8NoBom
value = JsonHelper.UTF8NoBom
Provides a UTF-8 encoding without a byte order mark (BOM).