mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-26 07:53:49 +00:00
Fix json compact (#9246)
This commit is contained in:
parent
f073b14fcc
commit
d13f7a4db6
1 changed files with 21 additions and 1 deletions
|
|
@ -17,6 +17,13 @@ public class JsonUtils
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions _defaultSerializeNoIndentedOptions = new()
|
||||||
|
{
|
||||||
|
WriteIndented = false,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
|
};
|
||||||
|
|
||||||
private static readonly JsonSerializerOptions _nullValueSerializeOptions = new()
|
private static readonly JsonSerializerOptions _nullValueSerializeOptions = new()
|
||||||
{
|
{
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
|
|
@ -24,6 +31,13 @@ public class JsonUtils
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions _nullValueSerializeNoIndentedOptions = new()
|
||||||
|
{
|
||||||
|
WriteIndented = false,
|
||||||
|
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
|
};
|
||||||
|
|
||||||
private static readonly JsonDocumentOptions _defaultDocumentOptions = new()
|
private static readonly JsonDocumentOptions _defaultDocumentOptions = new()
|
||||||
{
|
{
|
||||||
CommentHandling = JsonCommentHandling.Skip
|
CommentHandling = JsonCommentHandling.Skip
|
||||||
|
|
@ -104,7 +118,13 @@ public class JsonUtils
|
||||||
{
|
{
|
||||||
return result;
|
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);
|
result = JsonSerializer.Serialize(obj, options);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue