比如下面的 json 序列化代码
var json = JsonSerializer.Serialize(new { payload = new { paramStr = "{\"page\":1,\"pageSize\":10}" } });
Console.WriteLine(json);
时间输出是
{"payload":{"paramStr":"{\u0022page\u0022:1,\u0022pageSize\u0022:10}"}}
期望的输出是
{"payload":{"paramStr":"{\"page\":1,\"pageSize\":10}"}}
请问如何实现?
通过 JavaScriptEncoder.UnsafeRelaxedJsonEscaping 解决了
var json = JsonSerializer.Serialize(
new { payload = new { paramStr = "{\"page\":1,\"pageSize\":10}" } },
new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }
);
Console.WriteLine(json);