使用下面的代碼進行 json 序列化
class Program
{
static void Main(string[] args)
{
var json = JsonSerializer.ToString(new { title = "代碼改變世界" } );
Console.WriteLine(json);
}
}
輸出的中文被編碼了
{"title":"\u4ee3\u7801\u6539\u53d8\u4e16\u754c"}
請問如何讓中文不被編碼?
uj5u.com熱心網友回復:
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; set; }
這個屬性嗎
uj5u.com熱心網友回復:
JsonConvert.SerializeObject
uj5u.com熱心網友回復:
var options = new JsonSerializerOptions ();
options.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create (UnicodeRanges.All);
var json=JsonSerializer.Serialize (new { title = "代碼改變世界" }, options);
Console.WriteLine(json);
uj5u.com熱心網友回復:
太感謝了,我搞了一晚上人都瘋了,全網就找你這一個配置,太感謝了,我人已經徹底瘋了,哈哈呵呵哈。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/76587.html
標籤:其他技術討論專區
下一篇:U-net學習
