-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed as not planned
Labels
Author: Migration Bot 🤖The issue was created by a issue mover bot. The author may not be the actual author.The issue was created by a issue mover bot. The author may not be the actual author.DocsThis issue tracks updating documentationThis issue tracks updating documentationarea-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/Pages
Milestone
Description
This issue has been moved from a ticket on Developer Community.
Hi, I'm working on Blazor Server project and I wish to make special characters like Chinese not encoded, but when I config global setting it doesn't work, I have to apply setting for single JsonSerializer.Serialize
method, wondering did I do something wrong?
My dotnet version is 6.0.301 and I'm using VS 2022 17.2.1.
Program.cs
using System.Text.Encodings.Web;
using System.Text.Unicode;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder
.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs);
});
builder.Services.AddServerSideBlazor();
...
Index.razor
@jsonString
@code {
public string jsonString { get; set; }
protected override async Task OnInitializedAsync()
{
jsonString = JsonSerializer.Serialize(new
{
Name = "你的名字"
});
}
}
Original Comments
Feedback Bot on 7/4/2022, 10:35 AM:
(private comment, text removed)
Original Solutions
(no solutions)
Metadata
Metadata
Assignees
Labels
Author: Migration Bot 🤖The issue was created by a issue mover bot. The author may not be the actual author.The issue was created by a issue mover bot. The author may not be the actual author.DocsThis issue tracks updating documentationThis issue tracks updating documentationarea-ui-renderingIncludes: MVC Views/Pages, Razor Views/PagesIncludes: MVC Views/Pages, Razor Views/Pages