Home > other >  .net Core 3.0 is used in the System. Text. Json serialization of Chinese coding issues
.net Core 3.0 is used in the System. Text. Json serialization of Chinese coding issues

Time:09-26


Use the following code to json serialization
Class Program
{
The static void Main (string [] args)
{
Var json=JsonSerializer. ToString (new {title="code to change the world"});
Console. WriteLine (json);
}
}
The output is encoded in Chinese
{" title ":" \ u4ee3 \ u7801 \ u6539 \ u53d8 \ u4e16 \ u754c "}
How do I let not encoded in Chinese?

CodePudding user response:


https://github.com/dotnet/corefx/blob/master/src/System.Text.Json/docs/SerializerProgrammingModel.md
The JsonIgnore attribute specifies that The property is not serialized or deserialized.
[JsonIgnore] public DateTime? BirthDay {get; The set; }
This attribute

CodePudding user response:


JsonConvert. SerializeObject

CodePudding user response:


Var options=new JsonSerializerOptions ();
The options. The Encoder=System. Text. Encodings. Web. JavaScriptEncoder. Create (UnicodeRanges. All);
Var json=JsonSerializer. Serialize (new title="code" to change the world, attach the options).
Console. WriteLine (json);

CodePudding user response:

The
reference 3 floor response:
var options=new JsonSerializerOptions ();
The options. The Encoder=System. Text. Encodings. Web. JavaScriptEncoder. Create (UnicodeRanges. All);
Var json=JsonSerializer. Serialize (new title="code" to change the world, attach the options).
Console. WriteLine (json);


Thank you very much, I'm a night person crazy, tech-oriented , you will find this a configuration, thank you very much, I have been completely mad, ha ha ha ha ha,
  • Related