mirror of
https://github.com/Syping/ragephoto-cli.git
synced 2025-11-09 13:15:17 +01:00
put JsonSerializerOptions in SerializerOptions
This commit is contained in:
parent
dccd33bcf4
commit
348945ac0c
1 changed files with 7 additions and 6 deletions
13
Json.cs
13
Json.cs
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Text.Encodings.Web;
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
namespace RagePhoto.Cli;
|
namespace RagePhoto.Cli;
|
||||||
|
|
||||||
|
|
@ -69,9 +70,7 @@ internal class Json {
|
||||||
},
|
},
|
||||||
_ => throw new ArgumentException("Invalid format", nameof(format)),
|
_ => throw new ArgumentException("Invalid format", nameof(format)),
|
||||||
};
|
};
|
||||||
return json.ToJsonString(new() {
|
return json.ToJsonString(SerializerOptions);
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static String UpdateSign(Photo photo, String json) {
|
internal static String UpdateSign(Photo photo, String json) {
|
||||||
|
|
@ -79,13 +78,15 @@ internal class Json {
|
||||||
if (JsonNode.Parse(json) is not JsonObject jsonObject)
|
if (JsonNode.Parse(json) is not JsonObject jsonObject)
|
||||||
throw new ArgumentException("Invalid json", nameof(json));
|
throw new ArgumentException("Invalid json", nameof(json));
|
||||||
jsonObject["sign"] = photo.Sign;
|
jsonObject["sign"] = photo.Sign;
|
||||||
return jsonObject.ToJsonString(new() {
|
return jsonObject.ToJsonString(SerializerOptions);
|
||||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
Console.Error.WriteLine($"Failed to update sign: {exception.Message}");
|
Console.Error.WriteLine($"Failed to update sign: {exception.Message}");
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static readonly JsonSerializerOptions SerializerOptions = new() {
|
||||||
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue