From 77d49cf26c53688e683fb4c0eb537410566a3a53 Mon Sep 17 00:00:00 2001 From: database64128 Date: Sat, 6 Mar 2021 19:36:05 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9D=20object=20is=20deserialized=20as?= =?UTF-8?q?=20JsonElement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shadowsocks.CLI/ConfigConverter.cs | 39 ++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Shadowsocks.CLI/ConfigConverter.cs b/Shadowsocks.CLI/ConfigConverter.cs index be3eece4..24ad01da 100644 --- a/Shadowsocks.CLI/ConfigConverter.cs +++ b/Shadowsocks.CLI/ConfigConverter.cs @@ -55,8 +55,10 @@ namespace Shadowsocks.CLI if (sip008Links.Count > 0) { - var httpClient = new HttpClient(); - httpClient.Timeout = TimeSpan.FromSeconds(30.0); + var httpClient = new HttpClient + { + Timeout = TimeSpan.FromSeconds(30.0) + }; var tasks = sip008Links.Select(async x => await httpClient.GetFromJsonAsync(x, JsonHelper.snakeCaseJsonDeserializerOptions, cancellationToken)) .ToList(); while (tasks.Count > 0) @@ -108,18 +110,23 @@ namespace Shadowsocks.CLI foreach (var outbound in v2rayConfig.Outbounds) { if (outbound.Protocol == "shadowsocks" - && outbound.Settings is Interop.V2Ray.Protocols.Shadowsocks.OutboundConfigurationObject ssConfig) + && outbound.Settings is JsonElement jsonElement) { - foreach (var ssServer in ssConfig.Servers) - { - var server = new Server(); - server.Name = outbound.Tag; - server.Host = ssServer.Address; - server.Port = ssServer.Port; - server.Method = ssServer.Method; - server.Password = ssServer.Password; - Servers.Add(server); - } + var jsonText = jsonElement.GetRawText(); + var ssConfig = JsonSerializer.Deserialize(jsonText, JsonHelper.camelCaseJsonDeserializerOptions); + if (ssConfig != null) + foreach (var ssServer in ssConfig.Servers) + { + var server = new Server + { + Name = outbound.Tag, + Host = ssServer.Address, + Port = ssServer.Port, + Method = ssServer.Method, + Password = ssServer.Password + }; + Servers.Add(server); + } } } } @@ -168,8 +175,10 @@ namespace Shadowsocks.CLI /// A task that represents the asynchronous write operation. public Task ToV2rayJson(string path, CancellationToken cancellationToken = default) { - var v2rayConfig = new Interop.V2Ray.Config(); - v2rayConfig.Outbounds = new(); + var v2rayConfig = new Interop.V2Ray.Config + { + Outbounds = new() + }; foreach (var server in Servers) {