WebEnh

.net7 mvc jquery bootstrap json 学习中 第一次学PHP,正在研究中。自学进行时... ... 我的博客 https://enhweb.github.io/ 不错的皮肤:darkgreentrip,iMetro_HD
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Newtonsoft.Json解决中文编码问题

Posted on 2023-12-21 15:45  WebEnh  阅读(35)  评论(0编辑  收藏  举报

Newtonsoft.Json解决中文编码

默认Newtonsoft.Json序列化对象后,返回的中文未进行编码。

需要将编码转换的话,需要

1
2
3
4
5
6
7
var json = JsonConvert.SerializeObject(new
{
    uid = resultUser["uid"],
    usersign = resultUser["usersign"],
    price = price
    }, new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii
});

    其中: StringEscapeHandling = StringEscapeHandling.EscapeNonAscii 为关键代码