C
C#4mo ago
Ploot

✅ JsonSerializer ignoring encoding options?

This issue has been driving me crazy for the last hour. I have a json object that includes a string with an apostrophe in it, however it keeps getting converted to a unicode code. After some reading I found this was the default behaviour for the serializer and can be overridden with encoder options, however I have been totally unable to override this behaviour for some reason. This is the dotnetfiddle snippet I've been testing with https://dotnetfiddle.net/7VZABE. Am I doing something wrong here?
2 Replies
occluder
occluder4mo ago
@Ploot Doing
JsonSerializerOptions serializerSettings = new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
JsonSerializerOptions serializerSettings = new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
was the only way I could make it work there is a big red warning for doing this, however. https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/character-encoding#serialize-all-characters
Ploot
PlootOP4mo ago
Thank you :AA_Vanilla_Pray:
Want results from more Discord servers?
Add your server