1
using var graphQLClient = new GraphQLHttpClient(local, new NewtonsoftJsonSerializer());
var request = new GraphQLRequest{...}

var graphQLResponse = await graphQLClient.SendQueryAsync<ValueResponse>(request);            
return System.Text.Json.JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true });

return "abc" for english text field,

and "\u0422\u0435\u043A\u0443\u0449\u0438\u0439 \u0422\u04201" for russian text field

please tell me how to set encoding

a1olegs
  • 45
  • 3
  • 1
    You seem to be using two serializers, `NewtonsoftJsonSerializer` and `System.Text.Json.JsonSerializer`. Which one is causing the problem? If it's `System.Text.Json` then your problem is probably a duplicate of [dotnet core System.Text.Json unescape unicode string](https://stackoverflow.com/q/58003293/3744182) and [Issues with System.Text.Json serializing Unicode characters (like emojis)](https://stackoverflow.com/q/58738258/3744182). – dbc May 28 '20 at 15:29

1 Answers1

0
JsonSerializerOptions jso = new JsonSerializerOptions();
jso.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping;

var graphQLResponse = await graphQLClient.SendQueryAsync<ValueResponse>(request);

return System.Text.Json.JsonSerializer.Serialize(graphQLResponse, jso);
a1oleg
  • 73
  • 7