The exported routing rules are compatible with the import function of v2rayNG

pull/6465/head
2dust 2025-01-08 17:57:23 +08:00
parent 27c53be209
commit b770048f05
2 changed files with 33 additions and 1 deletions

View File

@ -97,6 +97,30 @@ namespace ServiceLib.Common
return result; return result;
} }
/// <summary>
/// Serialize Object to Json string
/// </summary>
/// <param name="obj"></param>
/// <param name="options"></param>
/// <returns></returns>
public static string Serialize(object? obj, JsonSerializerOptions options)
{
var result = string.Empty;
try
{
if (obj == null)
{
return result;
}
result = JsonSerializer.Serialize(obj, options);
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
}
return result;
}
/// <summary> /// <summary>
/// SerializeToNode /// SerializeToNode
/// </summary> /// </summary>

View File

@ -2,6 +2,8 @@
using ReactiveUI; using ReactiveUI;
using ReactiveUI.Fody.Helpers; using ReactiveUI.Fody.Helpers;
using System.Reactive; using System.Reactive;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace ServiceLib.ViewModels namespace ServiceLib.ViewModels
{ {
@ -189,7 +191,13 @@ namespace ServiceLib.ViewModels
} }
if (lst.Count > 0) if (lst.Count > 0)
{ {
await _updateView?.Invoke(EViewAction.SetClipboardData, JsonUtils.Serialize(lst)); var options = new JsonSerializerOptions
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
await _updateView?.Invoke(EViewAction.SetClipboardData, JsonUtils.Serialize(lst, options));
} }
} }