mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-17 20:54:36 +03:00
Fix json compact (#9246)
This commit is contained in:
@@ -17,6 +17,13 @@ public class JsonUtils
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions _defaultSerializeNoIndentedOptions = new()
|
||||
{
|
||||
WriteIndented = false,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions _nullValueSerializeOptions = new()
|
||||
{
|
||||
WriteIndented = true,
|
||||
@@ -24,6 +31,13 @@ public class JsonUtils
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
private static readonly JsonSerializerOptions _nullValueSerializeNoIndentedOptions = new()
|
||||
{
|
||||
WriteIndented = false,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
private static readonly JsonDocumentOptions _defaultDocumentOptions = new()
|
||||
{
|
||||
CommentHandling = JsonCommentHandling.Skip
|
||||
@@ -104,7 +118,13 @@ public class JsonUtils
|
||||
{
|
||||
return result;
|
||||
}
|
||||
var options = nullValue ? _nullValueSerializeOptions : _defaultSerializeOptions;
|
||||
var options = (nullValue, indented) switch
|
||||
{
|
||||
(true, true) => _nullValueSerializeOptions,
|
||||
(true, false) => _nullValueSerializeNoIndentedOptions,
|
||||
(false, true) => _defaultSerializeOptions,
|
||||
_ => _defaultSerializeNoIndentedOptions
|
||||
};
|
||||
result = JsonSerializer.Serialize(obj, options);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user